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(reactivity): ensure watch(Effect) can run independent of unmounted instance if created in a detatched effectScope (fix #7319) #7330

Merged
merged 2 commits into from Jan 9, 2023

Conversation

LinusBorg
Copy link
Member

close #7319

…d instance if created in a detatched effectScope
@LinusBorg
Copy link
Member Author

/cc @posva this should solve your problem in pinia.

Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

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

Nice! I think it would be even better to have 2 different count variables as it would make the test more robust

@LinusBorg
Copy link
Member Author

Good call, will do.

@posva posva self-requested a review December 13, 2022 09:12
@LinusBorg LinusBorg merged commit cd7c887 into main Jan 9, 2023
@LinusBorg LinusBorg deleted the linusborg/issue-7319 branch January 9, 2023 14:20
chrislone pushed a commit to chrislone/core that referenced this pull request Feb 4, 2023
…d instance if created in a detatched effectScope (fix vuejs#7319) (vuejs#7330)

* fix(reactivity): ensure watch(Effect) can run independent of unmounted instance if created in a detatched effectScope

* test: use separate counters for each watcher to make test more robust
zhangzhonghe pushed a commit to zhangzhonghe/core that referenced this pull request Apr 12, 2023
…d instance if created in a detatched effectScope (fix vuejs#7319) (vuejs#7330)

* fix(reactivity): ensure watch(Effect) can run independent of unmounted instance if created in a detatched effectScope

* test: use separate counters for each watcher to make test more robust
@yangmingshan
Copy link
Contributor

I think this PR may have hidden issues, especially for undetached effectScope. There are many other functions depends on currentInstance, like callWithErrorHandling queuePostRenderEffect etc.

watchEffect should be same as watch, maybe we can remove instance unmounted short circuit in watchEffect, since watch didn't have the same logic? I tried, no unit test fail.

If we need keep the short circuit for some reason, I think the better fix is:

getter = () => {
-  if (instance && instance.isUnmounted) {
+  if (currentScope && !currentScope.active) {
     return
  }
}

I also tried, all unit tests passed.

cc @yyx990803

@yyx990803
Copy link
Member

@yangmingshan PR welcome so we can take a better look and run ecosystem-ci if needed.

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.

watchEffect within effectScope is removed when component is unmounted
5 participants