Repository navigation
Commit 9865223
react-relay/rsc_EXPERIMENTAL: serverQuery and a synchronous useServerFragment
Summary:
Adds the `serverQuery` and `useServerFragment` APIs to `createServerEnvironment` from react-relay/rsc_EXPERIMENTAL. `serverQuery` executes a generated `server` query in the request-scoped Environment, resolves after its first payload, and keeps publishing later `defer` payloads into that Store. Calls with the same query and variables share the result at this level; an optional `AbortSignal` cancels the request.
`useServerFragment` reads a `server` fragment synchronously when its data is present, through an already-fulfilled thenable passed to `React.use`. A tree of synchronous server components can therefore render in the parent's Flight row without an artificial Promise tick for each read. Missing deferred data suspends; a request that fails, is cancelled, or ends without delivering the data rejects the pending read. A request or loader that never ends is not guaranteed to settle.
Reads use the Environment registered for the reference's owning request, so another same-request `createServerEnvironment` instance can read it after a hot reload. This does not introduce cross-request reference support.
The TypeScript declarations accept server-branded requests, operations and fragment keys, infer the response and `NoInfer` variables, and reject client-branded inputs. Existing `serverReadFragment` remains broad and unchanged.
Scope: server execution and reads only. Client data handoff, RSC Resolver fields and per-label deferred-error isolation are not added here. `serverPreloadQuery` and `useQueryFromServer` are unchanged; `useServerFragment` does not import `serverQuery`.
Reviewed By: evanyeung
Differential Revision: D126860282
fbshipit-source-id: 48357fca617275b8fbd42badeeb2c789403059b01 parent 04585d6 commit 9865223
8 files changed
Lines changed: 998 additions & 2 deletions
File tree
- packages/react-relay
- relay-hooks/rsc
- __tests__
- __generated__
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments