-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix watchFragment and useFragment incorrectly reporting complete: true for non-identifiable objects
#12335
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
base: main
Are you sure you want to change the base?
Fix watchFragment and useFragment incorrectly reporting complete: true for non-identifiable objects
#12335
Conversation
|
@ryo-manba: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
👷 Deploy request for apollo-client-docs pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 739b62f 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 |
❌ Docs preview failedThe preview failed to build. Build ID: ba84bc7fd4e44a0393adbc41 Errorsreact/api/react/components
|
|
Hey @ryo-manba 👋 Thanks for your patience! I'd actually like to dig a layer deeper and see if we can fix the issue at the root. It looks like anything having to do with a I can also reproduce the incorrect result using test.only("reports diffs incorrectly", async () => {
const cache = new InMemoryCache();
console.log(
cache.diff({
query: cache["getFragmentDoc"](gql`
fragment FooFragment on Foo {
foo
}
`),
id: cache.identify({}),
returnPartialData: true,
optimistic: true,
})
);
await new Promise((res) => {
const w = cache.watch({
query: cache["getFragmentDoc"](gql`
fragment FooFragment on Foo {
foo
}
`),
id: cache.identify({}),
returnPartialData: true,
immediate: true,
optimistic: true,
callback: (diff) => {
console.log("callback", diff);
res(void 0);
},
});
});
});If you paste and run this, you'll notice that From what I can tell, that Let's see if we can fix it in the cache itself. Is this something you'd like to look into further? |
|
Thank you for the information! |
watchFragment reports complete=false when from object is not identifiablewatchFragment and useFragment incorrectly reporting complete: true for non-identifiable objects
|
@jerelmiller |
|
Hey @ryo-manba 👋 Thanks a bunch! Let me put this up for discussion on our next team meeting. We are very close to releasing versions 3.14 and 4.0 very soon so we'll need to figure out where this change fits best. Thanks again for following through! |
|
Hey @ryo-manba! Thanks for your patience! We'd like to get this fix in 4.0, though after looking at this, we'd like to fix the I'll push some changes on top of this PR in the coming days to get that fix in place (I'm currently focused on writing some documentation for 4.0 before I can get to this). |
Closes #12003
Closes #11600
What
Fixes a bug where
watchFragmentanduseFragmentreturned{ complete: true }even when thefromobject could not be identified (i.e.cache.identify()returnedundefined).Now, in such cases, the result correctly includes
complete: falseandmissingfield info.Why
Previously, non-identifiable objects skipped fragment field checks, leaving
missingempty.This led to a false assumption that data was complete, causing confusing behavior in apps using partial data or suspense.
We now detect this edge case early in
InMemoryCache.diff()and return the correctcomplete: falseresult.This was created from the branch adds the failing test.
It might be better to merge that one first.