-
-
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
invalidate: callback not called for server load, invalidate never reloads server endpoints #6780
Comments
This is probably related to #6459 |
Not sure what's the best label for this / the best way to procede. We definitely should document it better though that |
I think it would be quite useful to be able to selectively re-fetch the page/layout endpoints (ie. each node) with invalidate. E.g., if I know that only the page data needs refreshing but none of the layout server data, I could call invalidate('the-url-of-the-page-server-load'). I'm not sure what the right naming schemes for those URLs would be (maybe something like |
|
This is intended behaviour. If you need to invalidate a specific |
Thanks for the feedback. I wasn't aware that I can use Frankly, I still find it a bit counter-intuitive that |
Unless I'm mistaken, Honestly, the dependencies/invalidation system was pretty mysterious to me before, and it's even more so now. Not blasting the changes at all, just hoping that this can be made more clear 😁 I stumbled here because I'm having issues with this myself. Prior to migration, I had a route that had a Migrated the |
That's what I thought at first, too, but I fired up a blitzstack project and was able to use depends in +page.server's load function, eg depends('app://test') Edit: I originally wrote here "The server side load (and only the server side load, not the isomorphic one) was triggered when I called invalidate('app://test').", but in fact triggering the server side load always triggers the isomorphic (shared) load as well. The server side load is not triggered when a dependency of the isomorphic load is triggered. |
Interesting! This is good to know, and makes sense now--thanks! But if that's the case, what mechanisms do we have for retriggering the server load? Is it only |
As I wrote, in your server |
Hmm, I think there may have been some wires crossed here--let me try to get on the same page! When I use "server load", I'm referring to the load fn inside of The load fn that has Taking a look at the StackBlitz you posted, the only time that I guess on some level I understand why it works this way, but I'm still wondering if |
The stackblitz in my original post does not reflect what I said in my later posts. Here's an example that shows different scenarios for invalidate: https://stackblitz.com/edit/sveltekit-selective-invalidation?file=src%2Froutes%2F%2Bpage.svelte (Note that I wrote earlier that triggering a server side load would not trigger the shared/isomorphic load if both are present, but that's not true. The shared load - if present - is always called when the server side load is called - which makes sense, because the server side data always has to pass through the shared load function and is not automatically merged into PageData.) BTW: yes "isomorphic load" refers to +page.ts or +layout.ts whereas "server load" refers to +page.server.ts and +layout.server.ts. BUT: I just realized that the typescript types are not complete - |
Ah, now it makes sense! Apologies for all the going around, and thanks for explaining! |
Filed the bug as #6929 |
The missing depends function is now fixed https://github.com/sveltejs/kit/releases/tag/%40sveltejs/kit%401.0.0-next.492 |
Describe the bug
I'm not really sure if this is intentional or a bug, but anyway:
invalidateAll
correctly triggers all load functions including calling the server side equivalents (+layout.server.ts, +page.server.ts).Accordingly, I would expect the callback passed to
invalidate
to be called with some URL that represents the server side load functions to selectively trigger a refetch of those resources. However, it is only called for URLs used in explicit fetch or depends calls in load functions. As a consequence,invalidate( () => true)
does not behave likeinvalidateAll
. I realize it's not documented to behave the same, but intuitively I'd expect it to.As a corollary, there is no URL that can be passed to invalidate (the non-callback version) that would reload the server side endpoints. The only way to trigger server side page/layout endpoints to reload is by using invalidateAll.
Reproduction
See https://stackblitz.com/edit/sveltejs-kit-template-default-zrzasd?terminal=dev
The page shows the timestamp of the data coming from different layers (server side layout load, layout load, server side page load, page load).
The button "Test invalidate" invokes invalidate and collects all URLs passed to the callback (note that the callback always returns false - we do not actually need to refresh anything for this test). The page shows the list of URLs that were passed to invalidate.
Note that the explicit dependencies "app://layout-load" and "app://page-load" show up in the list, but nothing more.
"Test invalidate with refresh" does the same but returns true from the callback. This causes the two load functions to run, but does NOT invoke the server side endpoints to be called. As a result, the server side data is missing from $page.data.
"Invalidate all" calls invalidateAll which refreshes all data as expected.
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: