-
Hi, I am new to react-query, so not sure I understand it correctly. This is the SSR example from your documentation:
As you can see, the current SSR implementation requires to manually prefetch all the data:
It would be nice to have it like apollo-client, that walks down the entire tree and executes every required query it encounters:
Is there a plan to implement a function like getDataFromTree() in react-query ? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 18 replies
-
I have no idea how this is implemented in apollo, but it's a very cool concept. If you know how to so it, let's talk about a contribution :) I'm guessing since this is server side code, it wouldn't even affect client bundle size, right? @Ephem fyi |
Beta Was this translation helpful? Give feedback.
-
I think this is already possible today using React Query with Suspense + react-ssr-prepass, which is a more performant implementation of a prepass render step than Apollo's one (at least last I checked). 🎉 When React 18 is released, while it wont have official support for Suspense data fetching, I think it might work out of the box with React Query as long as you are not streaming the response (or at least, as long as you don't hydrate the markup until you have the full response). If it does not work out of the box, I think that's where we should spend our effort instead of adding a prepass step, which is usually terrible for SSR performance. Also, even with Suspenseful SSR, for the best performance you will still want to start fetching those queries as soon as possible to avoid request waterfalls, so those prefetches will still be the best practice going forward, it's just that you can also start rendering earlier on the server. 😃 |
Beta Was this translation helpful? Give feedback.
-
If someone wants a reference implementation, I have one in tRPC here which works alright (and isn't using suspense. It's heavily based on urql's prepassing but isn't using suspense either. |
Beta Was this translation helpful? Give feedback.
-
This is pretty simple to implement and does not have to do with react-query or any additional package just use
And the next time you call any of the |
Beta Was this translation helpful? Give feedback.
I think this is already possible today using React Query with Suspense + react-ssr-prepass, which is a more performant implementation of a prepass render step than Apollo's one (at least last I checked). 🎉
When React 18 is released, while it wont have official support for Suspense data fetching, I think it might work out of the box with React Query as long as you are not streaming the response (or at least, as long as you don't hydrate the markup until you have the full response). If it does not work out of the box, I think that's where we should spend our effort instead of adding a prepass step, which is usually terrible for SSR performance.
Also, even with Suspenseful SSR, for the best …