Skip to content
Source
Sign inSign up
TanStack/router

loader staleTime is NOT respected AFTER router invalidation #2474

Send to my agent
Closedmstenq(GitHub profile, opens in a new tab) opened this issue 3 comments

Which project does this relate to?

Router

Describe the bug

While doing a simple todo sample app, after I added a todo, I called router.invalidate() so that the loader would fire and get the new todo, but once invalidate is called once, it appears that all routes are forever in the invalid: true state and the loaders run over and over. This is very noticeable when you have defaultPreload: "intent" set.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-8gggny?file=app%2Froutes%2Fposts.tsx

Steps to Reproduce the Bug or Issue

  1. Go to posts layout
  2. Hover over the post links and see in the terminal that all the loaders are fired
  3. Hover over the post links again, and you should see no loaders are fired
  4. Click the button labeled "Click here to Invalidate Router"
  5. Now hover over the links and you will see the loaders fire again, but the route is not marked as invalid: false so hovering/clicking over and over will fire the loader again and again.

Expected behavior

I would expect after doing router.invalidate() that the route loaders would fire again, but only once since I have defaultStaleTime set to Infinity.

Screenshots or Videos

https://github.com/user-attachments/assets/4a6c82d4-3ca4-45d4-8793-2b9ea7a3035d

Platform

  • OS: Windows & Stackblitz
  • Browser: Chrome
  • Version: 126

Additional context

No response

  1. I would expect after doing router.invalidate() that the route loaders would fire again, but only once since I have defaultStaleTime set to Infinity.

    https://github.com/user-attachments/assets/b8474468-732a-4b67-a8e6-1418011ece49

    @mstenq currently, when you run router.invalidate(), the loaders for the current active matches do get re-run.

    Could you please clarify exactly what is not working?

  2. @SeanCassiere In the video if you look at the terminal, you'll see that the queries all trigger on hover one time, then on second hover they don't trigger again. So far so good. Now if you invalidate, then hover over the links again, they fire again as expected. But they continue to keep firing every single time you hover over them or visit them. They never stop triggering the loaders from that point on. I would expect the route to be cached again, but it appears to me that once you trigger invalidate, the caching system never caches those routes again.

  3. SeanCassierecommented

    @mstenq thank you, that's given me a better understanding into the issue.

    In summary, once the router has been invalidated and the loaders have subsequently been reran, then the loader's staleTime is not being respected.

    Edit: Ideally, I think a reproduction should be added that's Router-only (not Start) to confirm that this bug is in Router-land only. However, at the onset, I'm pretty confident that this is a Router issue and not related to Start.

  4. SeanCassiere changed the title

  5. SeanCassiere changed the title

  6. SeanCassiere added labelsbug

Sign in to join this conversation.