-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ApolloContext: handling in React Server Components #10872
Conversation
🦋 Changeset detectedLatest commit: 2446ace The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks good. I had a couple questions, but nothing blocking. Thanks for making the library more resilient to new React features! 🔥
Note to self: As I based this on #10869, that PR needs to be merged before this PR. |
size-limit report 📦
|
The "per-React-Version-Singleton" ApolloContext is now stored on
globalThis
, notReact.createContext
, and throws an error message when accessed from React Server Components.Before this change, rendering an

ApolloProvider
or using any of our hooks, would have resulted in this error message.This error message is very specific to Apollo Client, and not easy to google.
So instead, now this error message is displayed:
Also, we do not try to store the "per-React-Singleton" version of
ApolloContext
onReact.createContext
any more, but store it inglobalThis[Symbol.for('__APOLLO_CONTEXT__')].get(React)
, which does not pollute thereact
module and will likely avoid similar problems in the future.For historical context why it was stored there, see #8798.
If all existing tests work, I would assume this is "tested enough".
Checklist: