Let's hear it for Remix. We built a high-performance loader API, very similar, right into the router, which allows you to ensure that data is ready, or at least getting ready, before any code from React is ever executed. In TanStack Router, however, loaders are isomorphic. They run on both the server during SSR and on the client before each navigation. They can prime caches, fetch assets, and even return their own data, which is then serialized to the client during SSR and rehydrated with your app.
This loader pattern is fantastic, and I've enjoyed using it over the years through Remix. But on its own, I believe it comes with some major drawbacks. One of them is most obvious. Say you were to leave this page and come back later. Are you really going to make your users wait for that loader again? I sure hope you wouldn't. So to solve this problem, our router needs to start understanding more about our data, and primarily how to cache it. At this point, I hope you're thinking what I'm thinking. Well, that sounds like a perfect job for TanStack Query. Woo! No. It would be great, and it will be. Just wait, though. Because normally, you would be right. It just felt wrong, though, to force you to use TanStack Query if you wanted to use Start, even though it's great. It also didn't feel right leaving TanStack Router in the dust on caching. If something simpler can do the trick, why not? So I did something really cool. I built a miniature version of TanStack Query right into the router. That's very cool. It's 5% of the size actually, and it's 5% the size of React Query. It's got built-in caching that's keyed on a combination of the path name and selected search parameters just like a query key. And with this tiny addition, the router now all on its own supports stale while we validate patterns, persistent pre-loading, granular validation, which means for your users, again, you'll have instant navigation, very few spinners, if any at all, and potentially even less bandwidth, depending on how you configure it.
So where does that leave TanStack Query? What if you want to use it? Well, we did more cool stuff. If you add TanStack Query, you'll get things like the polling, the infinite queries, offline support, optimistic updates, just naturally by using TanStack Query. It's great. But what I'm really excited about is how the UseSuspenseQuery integrates with router magically. It gives you isomorphic data fetching with a single hook.
Comments