-
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
ObservableQuery.getCurrentResult: skip the cache #10631
Conversation
…nent is unmount and remounted
if currently running the first query, started with a fetchPolicy meant to ignore cache results
🦋 Changeset detectedLatest commit: ee8dda5 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 |
@@ -7,5 +7,6 @@ | |||
"typescript.tsdk": "node_modules/typescript/lib", | |||
"cSpell.enableFiletypes": [ | |||
"mdx" | |||
] | |||
], | |||
"jest.jestCommandLine": "node_modules/.bin/jest --config ./config/jest.config.js --ignoreProjects 'ReactDOM 17' --runInBand", |
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 had to add this with some commit - the Jest VSCode plugin cannot display it when two projects run the same test twice, so I just set it to exclude the React17 tests. Also adds --runInBand
for the extension, which makes tests less flaky in general.
@@ -152,6 +154,7 @@ export class ObservableQuery< | |||
this.queryManager = queryManager; | |||
|
|||
// active state | |||
this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy); |
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 has to be initialized in the constructor, as getCurrentResult()
will be called before the ObservableQuery
is subscribed to for the first time.
@@ -421,7 +421,7 @@ describe('[queries] loading', () => { | |||
]); | |||
}, { interval: 1 }); | |||
await waitFor(() => { | |||
expect(count).toBe(6); | |||
expect(count).toBe(5); |
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 now rerenders one less time. I checked it - render 5 and 6 had identical this.props.data
, so this is probably a good thing:tm:?
(Tests are all green now, rerunning the test suite a third time. All that's red at this point is the file size.) |
size-limit report 📦
|
/release:pr |
A new release has been made for this PR. You can install it with |
I'm happy with the state of this now and have just added a ton of tests. Ready for review! |
/release:pr |
A new release has been made for this PR. You can install it with |
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.
Thanks for finally cracking this important puzzle @phryneas!
src/core/ObservableQuery.ts
Outdated
function skipCacheDataFor(fetchPolicy?: WatchQueryFetchPolicy) { | ||
return fetchPolicy === "network-only" || fetchPolicy === "no-cache" || fetchPolicy === "standby"; |
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.
Might be worth a comment that when typeof fetchPolicy === "undefined"
, that means cache-first
by default, so skipCacheDataFor
should return false
(as it does already).
Thanks for this guys, @benjamn do you have an ETA on this? |
@efstathiosntonas If nothing super-weird pops up, you can expect this to probably be in a patch release next week or the week after |
Co-authored-by: Ben Newman <ben@apollographql.com>
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This is my attempt at solving #10222.
The test is taken from @jerelmiller over in #10239.
I'm not sure if this covers all possible cases (what should happen if all of this plays out on a subsequent query? Is that even possible there?), but at least it gets all the tests green.
One of the HOC tests is now rerendering one less time, but not getting any new data.
I'll add a changeset if we decide that this solution is feasible.
Checklist: