facebook / facebook/relay

Support for React Server Components

Open
#4,599 16 comments 18 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.