Unexpected Loader Re-Requests on Current Route Hover with Preload ‘intent’
Why does the loader get re-requested every time I hover over a <Link> for the current route when the preload value is set to 'intent'? Is this intended behavior? When hovering over a <Link> for a different route, the request is not made again within the preloadStaleTime duration. I believe it should behave the same way.
3 Replies
other-emerald•2w ago
Hey @Lee, did you ever resolve this? I'm experiencing the same thing.
conscious-sapphire•2w ago
I haven't double checked this, but I believe that the "staleTime" on the router by default is 0, this means that loaders are not cached by default and will re-run whenever you hover a link to that route. This is to prevent duplicating cached data between the router cache and other cache (i.e. query cache).
You can set a default stale time for the router, or on a specific route using the
staleTime property on the route, which will then cache the loader for a given time, and only refetch when the dependencies change (i.e. search params, params, etc). Without a stale time, since the router isn't caching anything, it will always re-run loaders.
Note; you can see what is currently cached in the router dev tools under cached matchesother-emerald•2w ago
It's not a problem with staleTime -- it's ignoring preload and general stale time settings for links that point to the current location (or a partial match thereof).
This is what it seems we're experiencing:
- https://github.com/TanStack/router/issues/4112
- https://github.com/TanStack/router/issues/2980
Seemingly a bug from at least December 2024.