-
-
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
Parent Layout Data is not sent to page when invalidated by await parent()
#9355
Comments
This works as expected. The root layout does not have any dependencies on things like the URL which would make it rerun on a route change, the only dependency is the specific What's your use case? And what is your desired behavior? That the page load function can manually trigger a reload, or that the layout load runs on every page change? In the given example, you would want to rerun this on every page change, so you could opt into URL tracking by doing export function ({ url }) {
// ..
url.pathname; // opt into rerunning load whenever the url changes
} |
I don't want to rerun it on every page change, I want it to rerun when I tell it to. I want the behavior of My use case is for trpc-svelte-query's SSR. In the root layout, I return a |
Could you give a code example of what you expect this to look like? |
Simplified example:
export const load = ({ locals, depends }) =>.{
locals.map = new Map();
depends('ssr');
return { ssrData: locals.map };
};
export const load = ({ locals, invalidate }) =>.{
locals.map.set('key', await fetch(/* ... */));
invalidate('ssr');
}; |
I don't understand this example. Doing this would just override the This also uncovers a strong weirdness with that API: calling |
In my example, I assume that the parent function is always called first. In my actual code, both contain You might be overthinking the invalidate thing – it doesn't need to trigger any reruns in this case, it just has to behave identically to |
Here's an example without invalidate, depends, or overwriting the key I find it confusing that rerunning a load function doesn't guarantee the returned data is passed to page.data |
FWIW, While you check authorization and enforce in So My proposed solution now would be: Great that we have I opened another issue here #11415 which I close now, since we have this issue already. |
@dummdidumm I wrote a follow-up in the other thread #6315 (comment) and will reopen #11415 It would be great to have some way to auto-trigger a layout.server refresh on load func calls. |
We are experiencing the same behaviour. The |
I have a similar issue where after using
|
This comment was marked as off-topic.
This comment was marked as off-topic.
I've tested this on the latest version of SvelteKit and the parent load is re-run when a child load function depends on it through |
This example with the latest release still has the same issue: Expected:Server logs:
Actual:Server logs:
|
Ok, so the issue is awaiting the parent, but not returning the parent data, results in a stale |
Describe the bug
When a
+layout.server.ts
load function is re-ran on the server side viaawait parent()
, the data it returns is not sent down to the page.This should either be considered a bug since the function is called and the data is already calculated, but it is not sent to the page, or there should be some way to manually invalidate it on the server-side (
invalidate
is client-only).Note that
invalidate
does produce the expected result when called from the client.Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-xhrebt?file=src/routes/+layout.server.ts
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: