Question presented to candidate:
"Vue exports something called effectScope. What is it, what does it collect, and what exactly happens when you call stop() on it?"
What a strong answer should cover:
- An effect scope is a container: effects created synchronously inside
scope.run(fn)(watch,watchEffect, nested scopes) are recorded in it. scope.stop()stops every collected effect, runs everyonScopeDisposecallback and stops child scopes;scope.activebecomesfalse.- Scopes nest: a scope created inside another is stopped with its parent, unless created with
effectScope(true)(detached). - Every component instance has its own scope; that is how Vue stops a component's watchers on unmount.
getCurrentScope()andonScopeDispose()let library code find and hook into the active scope; Vue 3.5 addedpause()andresume().run()on a stopped scope warns and returnsundefined; the API arrived in Vue 3.2.
Clarifying questions expected:
- "Are we talking about the API itself, or how composables use it for cleanup?"
Code / implementation expected: Optional β create a scope with a watcher and a dispose callback, stop it, and show nothing fires afterwards.