r/reactjs • u/TkDodo23 • Aug 18 '26
Resource Reliable Query Prefetching with TanStack Router
https://tkdodo.eu/blog/reliable-query-prefetching-with-tanstack-routerš It's been way too long since my last blogpost. Today, I'm continuing my TanStack Router series with a pattern that I've been teaching in my workshops for over a year:
How to keep prefetches in sync between route loaders and components
94
Upvotes
10
u/Nick_Lastname Aug 18 '26
Great article as always
8
u/itzrvyning Aug 18 '26
I find these articles that discuss concrete, real world use cases so incredibly helpful.
2
u/Throwaway_0815_123 Aug 19 '26
Older articles show context injection via beforeLoad. Going forwards should one always use context or is there a still a use case where one would use beforeLoad for that?
3
u/clemwo Aug 18 '26
Very cool, I had this exact problem on a project I'm working on. Perfect timing, thanks for your article and your great work. Tanstack Router is so nice to work with!
2
u/Nick337Games Aug 19 '26
Lovely work!
2
u/rikbrown Aug 19 '26
This is a helpful pattern - thanks.
The future strict mode you mention in the article would be really great. I assume it would flag both preloads that arenāt used as well as queries that arenāt preloaded?
Something like this would be fantastic (albeit probably impossible) as a lint rule but even just something we could fail integration tests on would be nice. (Iām specifically thinking about features for our āharnessā, as I often see LLMs - and humans - making this mistake and it can be a bit hard to catch).
2
u/mattsowa Aug 19 '26
This is the exact problem I've been wondering how to solve recently, and this solution confirms my suspicions. Still, not without some disadvantages.
2
u/SeriaLud0 Aug 19 '26
Always look forward to a dodes post ā¤ļø