r/reactjs • • 1d ago

Resource 🗺️ Roadmap to Query v6 · TanStack query · Discussion #12669

https://github.com/TanStack/query/discussions/12669

📢 Please don’t get excited, but we’ve started working on TanStack Query v6. We’ll break things, but not too many.

Feedback appreciated 🙏

89 Upvotes

17 comments sorted by

29

u/avoid_pro 1d ago

A question from long time user - we need to standard, most optimal and not bloated way to deal with errors. Right now we can’t figure out one and unified way to handle them. We have tons of teams using query in their own way and errors are handled in completely differently. I personally like to create class component for every error, so I can pass error prop straight to error modal, without doing any extra steps. Others use throwOnError prop but this requires extra code.

What error handling strategy you would suggest so it would fit and could be used by many engineering teams?

18

u/TkDodo23 1d ago

this is still very much true:

https://tkdodo.eu/blog/react-query-error-handling#putting-it-all-together

what I personally like to do is show error toasts for background refetches (to keep the stale UI intact) and handle everything else locally or with Error Boundaries

I prefer error boundaries because they are the "react way" of integrating with errors. You need them anyways. Throw custom errors (subclasses of Error) if you want to convey more information like status code.

It's a larger migration for existing codebases but if you can integrate with useSuspenseQuery, which does this per default (throwing errors to error boundaries if there is no stale data to show) you can have your components focus on the sunshine case, and TypeScript will help because data can never be undefined.

7

u/Lumethys 1d ago

Better intergration with real-time tech like Websocket.

Recently i had to do quite a few of real time app, and many of the feature that is realtime would benefit greatly from Tanstack, but it was pretty awkward to use together

2

u/TkDodo23 1d ago

have you tried streamedQuery ?

3

u/TobiasMcTelson 23h ago

I tried without much success and with a lack of real examples. I even follow your 30+ posts about advanced react query (including 2-3 about WS). The thing is, one thing is the event transport layer like WS or SSE, other is 1. bidirectional communication in WS case, also 2. a good way to deal with delta updates.

I hope, Tanstack query, can deal better with those 2 points, as standardalone lib or with close, clear and example rich as Tanstack db adapter. I see even a possibility to integrate those event streams with pacer

3

u/bzBetty 13h ago

I’m excited to announce that....

Don’t get excited about major versions, please.

So you're allowed to be excited but we aren't?

2

u/TkDodo23 10h ago

Was waiting for this comment. This pun was intended, thanks for noticing 😂.

But there's also a bit of truth to it: I'm excited because we can drop deprecated stuff, make our codebase smaller, do some refactorings that we have postponed because they break query-core etc. Nothing about this is exciting to users of the lib 😅

3

u/sondr3_ 8h ago

This goes for most of the TanStack stuff, but I feel like the docs are slowly deteriorating and it's frustrating how much stuff I have to find in GitHub Discussions or in external blog posts instead of in the docs themselves. Router and Table is in my experience by far the worst, but Query is starting to have the same problems where the guides feel more like API reference docs with notes and are becoming very prescriptive, which makes it really hard to find solutions to things that are just barely off the happy path.

1

u/TkDodo23 7h ago

The only thing we've really changed lately is the API reference docs, as they are now exclusively generated from jsdoc comments in code. Users have wanted better jsdoc comments for a long time but keeping multiple sources of truth wasn't desirable. Format has changed and it might not be "better" than before because of all the cross references but we believe it's worth it and we're also working on making the generation better.

The guides I don't understand. They literally haven't changed in years. I wanted to re-structure them but never got around to doing it so really not sure what you're referring to but happy to improve if you have concrete feedback. PRs to the docs are also always welcome.

The thing with the docs is that they are mostly unbiased. They tell you what you can do. I can't (or rather won't) put my personal preferences in docs. That's why I have my blog. This has always been the case.

We will follow this up with skills and they will likely be more opinionated as you can't just tell agents to do what they want, this needs more bias.

But if I tell you, in the docs, that you should be e.g. using suspense queries, error boundaries, route loaders for prefetching and that you probably shouldn't use TanStack Query if you're using nextJs theRightWay™ I'm pretty sure I'd get a lot of negative feedback 😅.

2

u/sondr3_ 7h ago

As mentioned, Query has pretty good docs, the others... not so much. I would love if docs were more opinionated about things, docs should not just be an overview over all the things you can do but how to do them properly, what to avoid and so on. I've had to point my entire team to your blog for many different topics like query invalidation, query keys or integrating with Router that are in the docs but leave it up to the user to figure out how to use it... which leads to badly engineered solutions.

2

u/javatextbook 2h ago

Could you please not let LLMs create docs. Could those always remain human authored

1

u/TkDodo23 53m ago

I hand wrote every character of this roadmap :)

3

u/Kamensky124 23h ago

The removal of the imperative QueryClient methods is what my codebase will feel first in v6. We call ensureQueryData inside route loaders so first navigation resolves from cache without firing a network call, and per the v5 deprecation table those call sites map to query() with staleTime: 'static', while prefetchQuery call sites become query(...).catch(noop). None of that is hard, but dozens of loader call sites each carry their own error handling, so a mechanical migration matters more than the API shape. Are codemods planned for the v6 removals, or should teams budget for hand-auditing every loader call site?

-1

u/TkDodo23 23h ago

this should be very easily doable for an agent. Don't think that codemods are worth it.

1

u/BlazingThunder30 11h ago

Not everyone has acces to agents. Please provide codemods

4

u/leoniebuilds 22h ago

on the websocket side, what's worked for a lot of people is not fighting the cache and just pushing socket messages into it with setQueryData, so the query stays the single source of truth:

useEffect(() => {
  const off = socket.on('todo:updated', (todo) => {
    qc.setQueryData(['todos'], (old = []) => old.map(t => t.id === todo.id ? todo : t))
  })
  return off
}, [qc])

and set a longer staleTime for those keys so it doesn't refetch on every focus. for events you can't patch cleanly, just call invalidateQueries instead. an official helper for this pattern in v6 would be nice though.

1

u/nikola1970 1d ago

Let's go!