Observable doesn't fire when `notifyOnNetworkStatusChange` is true and data is reloaded but doesn't change
Issue Description
Hi. I believe I found a bug in ObservaleQuery.subscribe. I'm attaching a CodeSandbox repro, but it's essentially this code:
const observable = client.watchQuery({
query: ALL_PEOPLE,
notifyOnNetworkStatusChange: true,
});
observable.subscribe({
next: result => {
console.log("received result", result);
},
});
// Some time later
client.cache.modify({
fields: { people: (_, { DELETE }) => DELETE },
});
// Outputs:
//
// received result {data: {}, loading: true, networkStatus: 1, partial: true}
// ...and then nothing :(
Essentially we receive a "loading" event with no data, and then nothing afterwards. This means that the consumer of this observable is stuck in a loading state.
This works correctly if the if the data actually changes after a reload, which means that it's likely because of an optimization that prevents calling next when nothing changed. I think the logic of isDifferentFromLastResult needs to be modified.
When notifyOnNetworkStatusChange is false no event is fired, but that seems correct.
Link to Reproduction
https://codesandbox.io/p/devbox/tender-framework-68wm4d?workspaceId=7e27fe59-1d44-40f8-b1d0-beb23c6580e8
Reproduction Steps
No response
@apollo/client version
3.11.8
Hi there @PhoebeSzmucer 👋
Thanks for opening this issue! The reproduction is very clear, and this indeed looks like a bug. I've gone ahead and opened draft PR #12071 with a test that reproduces the issue. Our team is in the midst of conference season right now, but I hope to take a closer look soon. Thanks again!
I just ran into this issue and made a repro-case as well, before finding this. I'm gonna leave my reproduction here as well, for reference: https://github.com/diesieben07/apollo-cache-purge-repro
This seems to be fixed in 4.0.0-rc.1
@PhoebeSzmucer I believe we fixed this in the upcoming Apollo Client 4.0 release - could you give the RC a try and see if it solves the problem for you, too?
We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you!
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. For general questions, we recommend using our Community Forum or Stack Overflow.