SuspenseBoundary + multiple useQuery suspense:true - API calls are sequential #7254
-
I'm opening this as a discussion instead of as an issue because it's probably that I don't understand Codesandboxhttps://codesandbox.io/p/sandbox/react-query-suspense-forked-27twcw Expected behaviorI was expecting the API calls to be dispatched in parallel, and the Suspense boundary will be resolved once all of them had resolved. Current behaviorIt's quite different to what I expected. the 3 API calls are executed sequentially; which makes the user stay in the "Loading..." state for longer than expected. ![]() Notes
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
that's how suspense works. React sees that one hook wants to suspend, so it does. It doesn't know that there will be another hook that suspends. To get that, you'd need to split the See: https://tkdodo.eu/blog/seeding-the-query-cache#suspense-waterfalls |
Beta Was this translation helpful? Give feedback.
that's how suspense works. React sees that one hook wants to suspend, so it does. It doesn't know that there will be another hook that suspends. To get that, you'd need to split the
useQuery
calls up into multiple components, because they run in parallel in the same boundary.useQueries
also fixes this.See: https://tkdodo.eu/blog/seeding-the-query-cache#suspense-waterfalls