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

Observable doesn't fire when notifyOnNetworkStatusChange is true and data is reloaded but doesn't change #12069

Open
PhoebeSzmucer opened this issue Sep 20, 2024 · 1 comment
Labels

Comments

@PhoebeSzmucer
Copy link

PhoebeSzmucer commented Sep 20, 2024

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

@alessbell
Copy link
Member

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!

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

No branches or pull requests

2 participants