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

onScopeDispose is not called inside not immediate watchers #12681

Open
ferferga opened this issue Jan 10, 2025 · 1 comment
Open

onScopeDispose is not called inside not immediate watchers #12681

ferferga opened this issue Jan 10, 2025 · 1 comment

Comments

@ferferga
Copy link
Contributor

Vue version

3.5.13 (also tested on 22dcbf3 in Playground)

Link to minimal reproduction

https://play.vuejs.org/#__PROD__eNqNVE1vGjEQ/SuDLxBpyyptT4hETVOkplI/RJB68WVjhsWJ17bWNqFC/PeObb4LUW/rmTdv5o3fesXurO0vArIBGzrRSuvBoQ/2lmvZWNN6uDeNvYZZaxro9st0igXdHWAFbl4pZV7HOIP1BpkRXAujnYfGBO1xCjcH0J5vA15xPSxzX+pIB4+NVZVHOgEMn4L3RsMnoaR4ueFsz9PZfHJ2OzF1rTD3GJa5JJfn0Rfv5GxfyxmUlB2WB51YwbyjSWey7j87o2kZq0jAmSAGqbD9ab0kJZwNIGViLgn5lmJRSrGNizmKlzPxZ7eMMc5+teiwXSBnu5yv2hp9To8ef+CSvnfJxkyDIvQbyTE6o0KcMcM+Bz2lsQ9wadqHdGNS1xM3WnrUbisqDhqR64TnjK4vLu+S9P24H/ofUx3Xa9rizh2X7bQCox+FsfhFOmscFvBaeTEvDpxRAJHfh7ZF7RP0MPBAfqq0wAtOc7LWlTo22qxSLjqN69SqlzEF9K7g5jaLisVGYV+Zutf9fTe5/zoaw/UAxkF3ulQKJ1P3cu25Mqo6xnaviGCd+pclTObSEQBBKKx0sI5ISJjw6g88oaiCQ5Ae5pUD2TQ4lWTR7f3k8XPrZK1DCVlVf1GpgKR/e6Nnlb0fQGUtyO0uZ/RvTLsFdDr/LroXx7/MIzIa6P+xG6LOCVNaxobmv9dI1OfWWJCBTvYCcbdvvSJTuUgfAN83b0CMljl8/BCs/wIi+bb3

Steps to reproduce

  1. Open the playground and the console. You will see how the immediate "watcher 2" runs and watcher 1 does the same afterwards (because watcher 2 changes the variable it depends)
  2. Toggle the component: you will see how onScopeDispose from watcher 2 runs, but not the one from watcher 1

What is expected?

Both onScopeDispose callbacks are fired properly and both messages are printed to the console, regardless the immediate status of the watcher

What is actually happening?

The onScopeDispose is properly fired on both

System Info

No response

Any additional comments?

No response

@xfontr
Copy link

xfontr commented Jan 11, 2025

I don't have a specific solution for this but yes hopefully a debugging hint.

The immediate watcher is triggered even before the component is created. After that, the component is created. Once that happens, the non-immedate watcher is triggered. I assume that the fact this happens later affects the onScopeDispose actual scope, maybe focusing on the watcher itself rather than the component?

Here's how I tried this out: play.vuejs

Update:

I've tried to handle scopes explicitly with effectScope, but the results are exactly the same. The first time the immediate watcher runs it does get the scope. However, the second time (the mounting and creating of the component are done) it does not get the scope.

Either there's something I'm missing about Vue's scoping (which is very possible), or there's probably an actual issue/bug going on here.

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

No branches or pull requests

2 participants