Skip to content
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

Memoize Apollo Client #11699

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

justinadkins
Copy link

Closes #11602.

This PR adds memoization around the Apollo Client and its dependencies to prevent new clients being instantiated each time the provider is re-rendered. The only time a client will reinstantiate now is when the configuration has been modified.

If a client is reinstantiated, the previous client is now stopped to prevent a potential memory leak.

Note: The links that the client uses right now are unstable and were purposefully left out of the dependency array. Making links stable will require more effort that may not be necessary since the solution provided still updates them in a useEffect.

Copy link

@ryndshn ryndshn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Tobbe
Copy link
Member

Tobbe commented Oct 20, 2024

Thanks for the PR @justinadkins! I'll assign it to @callingmedic911 as he interacted with you on the issue you filed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug?]: Orphaned Apollo Client on RedwoodApolloProvider re-render
4 participants