-
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
Fix issue where queryRef
is recreated unnecessarily in strict mode
#11821
Conversation
…ck to Suspense cache in strict mode
🦋 Changeset detectedLatest commit: 7d5ff9f 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 |
@@ -203,6 +208,10 @@ export class InternalQueryReference<TData = unknown> { | |||
return this.observable.options; | |||
} | |||
|
|||
strictModeFixAddToSuspenseCache() { |
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.
I'm open to other names, but figured something like this makes it easier to understand the point of it.
size-limit report 📦
|
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
/release:pr |
A new release has been made for this PR. You can install it with:
|
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
After discussing this with @phryneas, I think the synchronous disposal might be more trouble than its worth. We've seen a couple issues pop up because of that change, and we're adding a TON more code just to get around that single There were two reasons that I switched from an async dispose to a sync dispose:
We discussed this a bit more and because we do not recommend that you share a client between tests, we'd be ok with the data leaking between tests. We always recommend that each test run its own instance of
This is a bit of an edge case, but the sync disposal allows for this more naturally. I don't expect this to happen often however and if it does, we have the Other than what's listed above, I don't have any strong reasons to keep the synchronous disposal. I believe its more trouble than its worth at this point, so I will update this PR to rollback to use the async disposal with the |
@jerelmiller thanks for that recap! Going back to the asynchronous disposal sounds like the right tradeoff here. We already note that client instances should not be shared between tests in our own docs, and I've opened a PR for this page https://mswjs.io/docs/faq/#apollo-client in the MSW docs to adjust the recommendation there: mswjs/mswjs.io#393. |
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.
🚀
Fixes #11815
Fixes a regression in 3.9.10 caused by #11738 that recreated the
queryRef
whenuseBackgroundQuery
would rerender. This could potentially cause many fetches when paired with afetchPolicy
that ignored the cache.NOTE: This change reverts most of the work done by #11738 which allowed queryRefs to be disposed of synchronously. This changed has caused too many headaches in strict mode and the amount of code added to avoid a
setTimeout
isn't worth it.