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

Fix edge case issue around unsubscribing live queries #4868

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

XiNiHa
Copy link
Contributor

@XiNiHa XiNiHa commented Dec 12, 2024

This only happens when...

  • A live query is passed to useLazyLoadQueryNode()
  • The initial fetch doesn't suspend
  • Two components subscribe to the same query with the same operation descriptor
  • The first subscribed component gets unmounted first

The fix is pretty simple though 😋

@@ -69,7 +67,7 @@ hook useLazyLoadQueryNode<TQuery: OperationType>({
fetchObservable,
fetchPolicy,
renderPolicy,
{start: startFetch, complete: completeFetch, error: completeFetch},
undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you help me understand why these are safe to remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was for calling .unsubscribe() when the component unmounts. However since the unsubscribe is now a no-op there's no point for keeping this anymore

},
};
observerStart(subscriptionWithConditionalCancelation);
unsubscribe: () => {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do live queries still get unsubscribed through some other means?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's managed by the .retain() stuff and is also ensured with the test added (the .toThrow() part)

@captbaritone
Copy link
Contributor

@XiNiHa I think I've been hesitant to merge this for fear that there are some edge cases I'm not aware of here and that it could break things when I roll it out. Would you be willing to add this change (fix) behind a feature flag?

export type FeatureFlags = {

@captbaritone
Copy link
Contributor

@XiNiHa Curious if you'll be able to add a flag here.

@XiNiHa
Copy link
Contributor Author

XiNiHa commented Feb 5, 2025

Oops, missed the notification 😅 Will make it done today

@XiNiHa XiNiHa force-pushed the fix-live-unsubscribe branch from b7dc565 to 2890ce1 Compare February 5, 2025 04:51
@XiNiHa XiNiHa force-pushed the fix-live-unsubscribe branch from 2890ce1 to 3a012df Compare February 5, 2025 05:03
@XiNiHa XiNiHa force-pushed the fix-live-unsubscribe branch from 3a012df to 2a9058d Compare February 5, 2025 05:09
@XiNiHa XiNiHa marked this pull request as draft February 5, 2025 05:30
@XiNiHa
Copy link
Contributor Author

XiNiHa commented Feb 5, 2025

The test started to pass even without the fix 🤔 let me figure out what's happening...

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

Successfully merging this pull request may close these issues.

3 participants