-
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
ApolloProvider causing rerenders in consumers if ApolloProvider is rerendered even with the same client argument #7626
Comments
Running into this issue as well on latest npm apollo 3.4.16 |
Facing same issue. |
@tathagat2000 thanks for the ping - a fix for this will go out in 3.8 - see #10869 |
Thank you @phryneas |
* add failing tests * ApolloProvider: ensure context value stability fixes #7626 * adjust bundlesize * ApolloContext: handling in React Server Components * feedback from code review
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Intended outcome:
Whenever
ApolloProvider
is rerendered (e.g. if the parent rerenders) but receives the sameclient
, this should not cause the context (used byuseQuery
,useMutation
, but also the consumers) to force a rerender.I tried to use
ApolloProvider
to provide the Apollo Client inside a separate React environment (React-Konva). I tried to utilize the new type policies to prevent passing down props by using queries that fetch data from the cache directly by id. All this again to optimize the rather slow React-Konva scene. However, even without the cache changing, simply moving the scene around (which rerenders the parent component of ApolloProvider and thus ApolloProvider itself) caused all objects in the scene with queries to rerender.Actual outcome:
Instead of objects not being rerendered as long as no data changes in the Apollo cache, all objects rerender whenever something changes up regardless of whether
client
remains the same.How to reproduce the issue:
Create an
ApolloProvider
in a component that will rerender, notice that all memoized components deeper down in the tree still rerender even when the stored cache value doesn't change. For a working example (with an alternative that doesn't have this issue) see:https://codesandbox.io/s/apollo-context-rerenders-umlrx
From what I gather, the following happens:
if
to execute (value === undefined/null
).if
usesObject.assign({}, context, { client })
to create a context.context
is different and React will rerender all context dependent components, causing this issue.Locally, I fixed this by simply using my own provider:
I don't need the reuse feature from ApolloProvider here so this is sufficient for my use case. But I believe it's useful to cache the
context
object value so the (potentially many) consumers don't needlessly rerender.Versions
The text was updated successfully, but these errors were encountered: