Replies: 5 comments 31 replies
-
the
yes this should be doable as a minor
we can do this as soon as
like it 👍
my first instinct is:
one bigger question from my side would be: Do we want a dedicated This would be beneficial for TypeScript users because right now, |
Beta Was this translation helpful? Give feedback.
-
This is really interesting, thanks for sharing! I'd be curious if you have ideas how existing APIs that rely on React Context will work on the server side (e.g. I just saw the new SSR guide where you're using the |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm the author of Rakkas, a Vite-based React metaframework with some unique cutting edge features. It doesn't support RSC yet but it has supported streaming SSR with Suspense for quite sometime now (before Next.js did). I have a Rakkas-Tanstack Query integration example repo in which I devised a scheme to make Tanstack Query work with streaming SSR. I thought it might be of interest in this discussion. I just added some documentation on how it works in the readme but, basically, instead of relying on Tanstack Query's own deydration/hydration features, I handle the serialization myself: Every time a query is resolved on the server, I inject a script into React's HTML stream that calls It may also be of interest that Rakkas has its own implementation of Lastly, you may want to check out @brillout's |
Beta Was this translation helpful? Give feedback.
-
To whom this may concern,
I do not know why I am receiving all of these notifications. I did not
subscribe to follow or receive anything. Can someone advise as to how this
may have happened?
Thanks
…On Mon, Jan 23, 2023 at 10:04 AM Artem Malko ***@***.***> wrote:
Hm, @brillout <https://github.com/brillout> could you explain, how use()
can replace react-streaming?
—
Reply to this email directly, view it on GitHub
<#4623 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASZ5GK7EUP4U73E6JWJCL6LWT2MYZANCNFSM6AAAAAAS35WEUA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Prefetching now can happen in multiple server components, how would you collect all of them together to the right |
Beta Was this translation helpful? Give feedback.
-
Improve React Query hydration, Streaming SSR & Server Components
For everything below, we also need to figure out a holistic API that makes sense, that we can build on in the future and with a solid migration path. Hopefully(/probably) APIs won't change too much/be incrementally adoptable, I think most work happens in the background, but that there will be new patterns to learn for users that want to leverage new features.
This is not (yet) an API design document, but I've added some examples of my current thinking at the bottom.
Note that I think a big goal of Query is to have a framework agnostic core to be able to support other frameworks than React. It already has a great custom cache, so the plan is to keep building on that and not really rely on the upcoming React cache APIs except where we have to, for specific things like request scoped things, the fetch-deduplication etc. This might be subject to change of course.
General stuff
'use client'
in the correct places (minor?)use()
instead of throwing Promises (minor/major?)useSyncExternalStore
should have a correct/frozengetServerSnapshot
(minor)useEffect
for queries that someone is actively listening to since this results in re-renders/observable side effectsuseEffect
also add the new data to a context for that subtree, refactor all reads to patch in data from that context. That subtree safely gets the new data during the same render instead of after, "true" cache and thus anything listening outside of that subtree gets updated via theuseEffect
(This might be overkill, we should evaluate if step 1 is good enough first)<Hydrate>
to<HydrationBoundary>
(? open to other suggestions, and we can deprecate and keep the current one for migration purposes), for three reasons:useQuery(..., { suspense: true })
with SSR Streaming (see below), we might need to support some kind of "automatic, in the background de/rehydration" tied to a specific position in the tree. Also, matching aSuspense(Boundary)
,ErrorBoundary
andHydrationBoundary
together feels like it makes sense?hydrate()
(should stay for other frameworks) and the hookuseHydrate
(deprecate/remove?)Server Side Rendering
useQuery(..., { suspense: true })
to work out of the box as long as you buffer all the content instead of streaming? Pretty sure this is possible in custom setups, but not sure about metaframeworks.useQuery(..., { suspense: true })
to work with streaming SSR (withoutawait prefetch()
that same query before rendering). Missing primitives in React? (Linked question in the RSC WG: #3)Server Components
queryClient
even necessary here, or should we implement a lightweightprefetch()
API instead?queryClient
to avoid duplication etc, we probably want to use the per requestcache()
API that is for now only documented in the Next beta docs. Not sure that this is necessary though, especially as a first step since it probably adds a bunch of complexity.API Examples
This is not thought through or fleshed out yet, just early spitballing to start a discussion. It all depends a lot on what final low level APIs will be available from React(/the metaframeworks) and what they will look like, but I consider it a decent guess based on what we know.
Basic hydration
No Suspense, no streaming, no RSCs, just what's always been available.
Streaming SSR without prefetching
This probably needs primitives from React we don't have or know anything about yet, but those should(?) be transparent to the user, so we can still imagine an API.
Optionally, the
Page
component above could start aprefetchQuery
, but notawait
it, just to kick off loading earlier. Some details to work out around that case (does it need to bequeryClient.prefetchQuery
in this case, or can we rely on the fetch cache here as well as in RSCs, should/can that prefetch happen in aloader
function before rendering, or in render (since it's an idempotent side effect), etc?)Server Components
What did I miss?
This is somewhat of a braindump on my current thinking, it's not well researched or thought through in all aspects, so take it as a starting point. Please challenge everything you can think of, tell me where I'm wrong, ask questions on anything that is unclear and join in the discussion!
Beta Was this translation helpful? Give feedback.
All reactions