-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow maxage in layouts load #1515
Comments
I guess when the page component and layout specify different maxages that you'd want the child to override |
But yeah, we also use it to cache the result of calling Hear me out: we already have a mechanism for caching network requests — I think getting rid of that behaviour would make things simpler externally, and more consistent and understandable externally. But we would need to implement #4625 first. |
Just wanted to add another voice of support for cleaning this up. I also ran into the cache maxage issue on I think removing that feature entirely and then documenting why it has that behaviour (as per Rich's comment above) and alternatives (eg: cache-control and/or link to userland solution like context) would be a good move. Especially since it'll help bridge the gap between how pages and how layouts work, the finer details of which have caught me out a few times (see also: shadow endpoints for layouts). Emphasis on the documentation though, I feel like since Sveltekit is moving so fast towards v1 a lot of these features get stripped or changed with only barebones documentation on API basics rather than documentation on how to achieve common use cases like this the "sveltekit way" |
#5778 added a |
Is your feature request related to a problem? Please describe.
Layouts cannot cache the return value of their load function, as seen in the docs. If the function fetches an endpoint it will be called each time a link is clicked or prefetched.
Describe the solution you'd like
load()
function in a__layout.svelte
can return amaxage
property to cache its return value, just like indexes can do.Workaround : return a context in the layout load function then use it along maxage in each children indexes.
With this simple structure, 2 main pages containing 2 tabs each (meaning each sibling tabs share the same data), the parent layout seems like a good place to fetch this data:
I would love to be able to cache both data.json from the layouts. Navigating from
cat/xxx
todog/xxx
would not trigger a fresh fetch beyond the first visit.Describe alternatives you've considered
[maxage] only applies to page components, not layout components.
How important is this feature to you?
I can live without it especially because the workaround is easy, if not feasible I feel like the docs should explain why in that case.
The text was updated successfully, but these errors were encountered: