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

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

Conversation

XiNiHa
Copy link

@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
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
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)

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