Replies: 2 comments 1 reply
-
After a discussion with one of the React maintainers, turns out that using However, there is also, technically, a possibility to let
This begs the question: will the dynamically imported AFAIK, @TkDodo, you might have the expertise to help close the issue 🙏 |
Beta Was this translation helpful? Give feedback.
-
I want to maybe go away from exposing a dedicated
this already exists as an experimental feature. Maybe you can try out that. Note: you have to set |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I've been trying to create a component which would encapsulate data loading logic, to have the most granular approach to using
<Suspense/>
, avoiding UI duplication with skeletons. My goal was to have one component which would handle suspending, fallback UI, loading, polling, errors, etc, and be used in a server component like so:This, afaik, would result in everything but the suspended value being pre-rendered server-side, eliminating the need to care about large skeletons, duplicating layout components or what not. Thought that would be neat?
I have arrived at a working solution, but a hacky one, as it used
throw
to trigger<Suspense />
. When it struck me that we now have theuse()
hook to handle exactly what I thought was needed – keeping a component suspended while dynamically importing a query. However, when I tried using it I saw:Error: Update hook called on initial render. This is likely a bug in React. Please file an issue.
Even though it seems to function. The data fetch is fired on the server, response is streamed to the client, where the
useSuspenseQuery
hook proceeds to poll and update the value.I am well aware this whole approach might be DoA because it might break something under the hood of the
useSuspenceQuery
itself. Or that it might be a React bug – R19 is not out yet after all! However, since I haven't seen anyone trying to achieve all this, considered it would be useful to bring it up here anyways :)TLDR:
use()
hook?Your minimal, reproducible example
https://codesandbox.io/p/devbox/6xmt4y
Steps to reproduce
See the Sandbox 🫡
Expected behavior
Work with
use()
like it does without it.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Likely not relevant
Tanstack Query adapter
react-query
TanStack Query version
5.59.20
TypeScript version
5.6.3
Additional context
Using
"@tanstack/react-query-next-experimental"
Related issue
facebook/react#31640
Beta Was this translation helpful? Give feedback.
All reactions