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.
Are there any objections to this or other ideas? Otherwise I'll try to create a proof-of-concept over the coming weeks.
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
useFragmentto 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
cacheAPI on the server. Maybe we could define thatuseRelayEnvironmentconsumes the environment from a React cache instead of context in server-components or on the server in general. This could be achieved through thereact-serverconditional export.Are there any objections to this or other ideas? Otherwise I'll try to create a proof-of-concept over the coming weeks.