Replies: 5 comments 14 replies
-
It's hard to say what the issue is without an example of the load function in question -- can you show some code? |
Beta Was this translation helpful? Give feedback.
-
I have the same issue. My load functions rerun on every navigation (e.g. clicking to a new route and back, or even hitting back in the browser). It's as though invalidate is called on every navigation even though I'm doing nothing to trigger an invalidation? Maybe dependencies aren't being tracked properly by SvelteKit? An example of one of my load functions: export const load = async ({ locals }) => {
return {
postData: db.getPostData(locals.user?.id)
};
}; The only dependency is locals, and I've verified that nothing in locals is changing between navigations, but load still always reruns |
Beta Was this translation helpful? Give feedback.
-
I'd like to help, but it seems like maybe there is just a misunderstanding of how a route is invalidated or when load functions re-run. It would really help if you could spin up a repl or similar. I'm guessing there is just a misunderstanding and not a bug in SvelteKit, but I could be wrong. |
Beta Was this translation helpful? Give feedback.
-
I think the issue (and I only know this because a co-worker pointed it out when I did something similar) is that you're depending on |
Beta Was this translation helpful? Give feedback.
-
Hey, I wanted to reference my discussion (#13074) here, because I think I might be having the same issue as you guys. I think any page load function is always rerun when navigating from a different page. Only the result of shared layout load functions are reused and not rerun if their dependencies did not change. The result of page load functions is only reused (at least I think) when the user navigates to a different route which renders the same dynamic page. For example in the example in the documentation they mention the user navigating from Although it's not clear to me from the documentation, so I'm hoping someone in the know can confirm this hypothesis. At least you can check out my discussion to see my workaround: caching data in the browser. |
Beta Was this translation helpful? Give feedback.
-
When I navigate to page/route like from navbar (which has preload data attribute) it invalidates and re-runs the load function on every navigation, this is not actually what I want in some cases, (It happens even if my load function doesn't follow the cases where invalidation takes place automatically (mentioned in docs) ) , this actually makes fetch requests pending resulting slow navigation or delayed rendering of the page, What would be the cause here?, Thanks!
Beta Was this translation helpful? Give feedback.
All reactions