Navigating while refetch is in progress results in cache not being used
I was wondering if the behavior I am observing is a bug, or if I am doing something wrong.
When defining a loader with long loading time I see the stale data as expected when navigating to the route from another route. The navigation also correctly triggers the refetch of the stale data.
Now when I navigate to another route after triggering the refetch without waiting for the refetch to be done, and navigating back to the route immediately, I don't get the stale data, but instead have to wait for the loader to be done.
Debug Tools show the stale loaderData with the 'fetching' status, so it seems like cached data should be there for display.
Is this behavior expected? If so, what's the reason behind this? I'd love to understand the internal logic and maybe even contribute if this turns out to be a bug 🙂
6 Replies
sensitive-blue•7mo ago
can you please fork one of the existing stackblitz router examples , reproduce your setup and provide detailed instructions?
stormy-goldOP•7mo ago
Sure thing. Probably should've done that directly: https://stackblitz.com/edit/tanstack-router-wczba6rg?file=src%2Froutes%2Findex.tsx
I also recorded the behavior. But maybe a short description of the video helps:
When I first visit the page I see nothing as long as the loader is loading which is normal.
Then I click the link to visit the
/about page and immediately navigate back to the / page.
Now the loader is fired again, but during the loading time the stale data (0.600...) is displayed until the loader is done after which the new data (0.942...) is displayed which is also as expected.
Next I again navigate to the /about page and back which shows the same behavior (we see the stale data 0.942...), except this time I navigate to /about again while the loader is still loading. Trying to navigate back this time doesn't show the stale data (0.942,,,) but 'blocks' as if there was no data. But we still should have the stale data we could show right?sensitive-blue•7mo ago
probably a bug
can you please create a github issue out of this?
next step would be to add a failing test (ideally unit test)
stormy-goldOP•7mo ago
Alright, I'll create an issue and see if I can also do a failing unit test 🙂
Ok so I created the issue along with a PR for a unit test reproducing the behavior:
https://github.com/TanStack/router/issues/4245
https://github.com/TanStack/router/pull/4246
Anything else?
sensitive-blue•7mo ago
added a comment
I expect this behavior to also exist on the alpha branch but can you please test?
stormy-goldOP•7mo ago
Fixed the test. And also ran it on alpha. Same behavior