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: unsubscribe needs to be called #86

Closed
wants to merge 1 commit into from

Conversation

peterferguson
Copy link
Contributor

@peterferguson peterferguson commented Aug 13, 2024

The unsubscribe function should either be called or removed since it is immediately followed by a reset of the observer which runs removeObserver without the hasListeners guard of unsubscribe.

Arguably it is better to only call unsubscribe and remove the reset. Can update the PR if you agree

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@kalijonn
Copy link
Collaborator

The unsubscribe function needs to be removed. Tanstack query creates a new observer when a component is unmounted and remounted again. In jotai, we keep the observer even when unmounted. To achieve the same behavior as creating a new observer, we are resetting the observer. This causes the mutation (in the observer) to be set to undefined. On mount, the subscription happens again leading to the observer now observing a new mutation.

I have cleaned it up as part of #91

@kalijonn kalijonn closed this Aug 18, 2024
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.

2 participants