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

Fixed issue causing inactive queries to be executed when clearing or resetting the store #11925

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Cellule
Copy link

@Cellule Cellule commented Jul 4, 2024

Closes #11914

Copy link

netlify bot commented Jul 4, 2024

👷 Deploy request for apollo-client-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 187828a

Copy link

changeset-bot bot commented Jul 4, 2024

🦋 Changeset detected

Latest commit: 187828a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

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

@jerelmiller jerelmiller self-requested a review July 5, 2024 21:38
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the fix you presented here is a reasonable one and I'm good with that fix!

Where I'd like to see a change potentially is how we setup the test to reproduce this behavior. See my comments on the tests and let me know what you think!

import { equal } from "@wry/equality";
import type { DocumentNode, GraphQLError } from "graphql";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like your editor might have applied some kind of import reordering. Would you mind disabling that and reverting the changes to the imports? We'd love to keep the git blame as clean as possible 🙂

@@ -1,53 +1,53 @@
// externals
import { DocumentNode, GraphQLError } from "graphql";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Would you mind reverting the change that reordered these imports?

});
// Recreate state where an observable query is dirty but has no observers in the query manager
// @ts-expect-error -- Accessing private field for testing
oq.queryInfo.dirty = true;
Copy link
Member

@jerelmiller jerelmiller Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this no doubt reproduces the issues, I'd still love to figure out how best the client gets into this state to begin with using user-facing APIs. User's aren't going to be touching QueryInfo or the dirty flag manually, so the more we can understand the situation that gets us here, the better. It will help us avoid a regression in the future knowing exactly the situation that got us here.

Since we are able to reproduce in CodeSandbox using useQuery with React's strict mode enabled, we should consider moving this test over to the useQuery tests. Maybe we start there to figure out exactly how this dirty flag gets set and work backwards?

Once we have a failing test for useQuery ("failing" means assuming the change you've added to QueryInfo is not applied), then we might figure out how best to backport the situation over to this test.

What do you think about that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to reproduce the bad state, regardless of what causes the bad state
I agree that it's better to do a fully functional test especially to identify the "real" cause of the issue, but I haven't had time to look into it this week because I was swamped and I'm going on vacations starting next week.

If you want to pick up the PR to wrap it up I don't mind.
Otherwise I'll try to look into it when I get a chance (it's still on my list 😅)

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

Successfully merging this pull request may close these issues.

resetStore can cause to refetch unmounted/inactive queries
2 participants