Support for React Server Components
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Today you can't use Relay with React Server Components, because the RelayEnvironment is handed around using React Context.
Most of our components will still remain client-only, but there are some of our pages that would benefit greatly from being statically pre-rendered using React Server Components. In these components we'd also like to use Relay's `useFragment` to be able to re-use existing fragments and developer knowledge.
Since the Relay Environment context is basically just a dependency injection mechanism, it could also be replaced by React's `cache` API on the server. Maybe we could define that `useRelayEnvironment` consumes the environment from a React cache instead of context in server-components or on the server in general. This could be achieved through the [`react-server` conditional export](https://github.com/reactjs/rfcs/blob/main/text/0227-server-module-conventions.md#react-server-conditional-exports).
Are there any objections to this or other ideas? Otherwise I'll try to create a proof-of-concept over the coming weeks.
Contributor guide
Assessment
This issue has not been assessed yet.