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

change re-subscription order #11431

Merged
merged 2 commits into from
Dec 15, 2023

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Dec 15, 2023

fixes test "useReadQuery auto-resubscribes the query after its disposed", but breaks the next one 😓 (fixed it 🎉 )

CC @jerelmiller take a look :)

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

fixes test "useReadQuery auto-resubscribes the query after its disposed"
Copy link

changeset-bot bot commented Dec 15, 2023

⚠️ No Changeset found

Latest commit: 14d680a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines -214 to -215
// Avoid triggering reobserve when resubscribing
observable["observers"].add(observer);
Copy link
Member Author

@phryneas phryneas Dec 15, 2023

Choose a reason for hiding this comment

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

observable.filter in the next line will call observable.subscribe internally anyways, and we can prevent the request in the no-cache case by temporarily setting fetchPolicy to "standby"

Comment on lines -217 to -221
this.subscription = observable
.filter(
(result) => !equal(result.data, {}) && !equal(result, this.result)
)
.subscribe(observer);
Copy link
Member Author

Choose a reason for hiding this comment

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

moving this up as the .subscribe will lead to fetchConcastWithInfo call Querymanager.getQuery, which will create a new queryInfo object (which is required to call forceDiff)

if (originalFetchPolicy !== "no-cache") {
observable.resetLastResults();
observable.forceDiff();
Copy link
Member Author

Choose a reason for hiding this comment

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

forceDiff here would create a subscription for observable. queryInfo, which at that point in time is a unregistered, old queryInfo.

make "useReadQuery handles auto-resubscribe on no-cache fetch policy" test pass
@phryneas phryneas marked this pull request as ready for review December 15, 2023 14:34
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.

Will make some tweaks in my branch, but thanks for digging into this for me!

@jerelmiller jerelmiller merged commit 8cd67f0 into jerel/load-query-outside-react Dec 15, 2023
24 of 27 checks passed
@github-actions github-actions bot added the auto-cleanup 🤖 label Dec 15, 2023
@jerelmiller jerelmiller deleted the pr/fix-resubscribe branch December 15, 2023 18:27
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants