Skip to content

Commit 7161176

Browse files
committedAug 18, 2022
fix: fix effect scope tracking for manually created instances
fix #12705
1 parent 165a14a commit 7161176

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed
 

‎src/core/instance/init.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function initMixin(Vue: typeof Component) {
3434
vm.__v_skip = true
3535
// effect scope
3636
vm._scope = new EffectScope(true /* detached */)
37+
vm._scope._vm = true
3738
// merge options
3839
if (options && options._isComponent) {
3940
// optimize internal component instantiation

‎src/core/instance/lifecycle.ts

-2
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,13 @@ export function mountComponent(
209209
// we set this to vm._watcher inside the watcher's constructor
210210
// since the watcher's initial patch may call $forceUpdate (e.g. inside child
211211
// component's mounted hook), which relies on vm._watcher being already defined
212-
vm._scope.on()
213212
new Watcher(
214213
vm,
215214
updateComponent,
216215
noop,
217216
watcherOptions,
218217
true /* isRenderWatcher */
219218
)
220-
vm._scope.off()
221219
hydrating = false
222220

223221
// flush buffer for flush: "pre" watchers queued in setup()

‎src/core/observer/watcher.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,16 @@ export default class Watcher implements DepTarget {
7171
options?: WatcherOptions | null,
7272
isRenderWatcher?: boolean
7373
) {
74-
recordEffectScope(this, activeEffectScope || (vm ? vm._scope : undefined))
74+
recordEffectScope(
75+
this,
76+
// if the active effect scope is manually created (not a component scope),
77+
// prioritize it
78+
activeEffectScope && !activeEffectScope._vm
79+
? activeEffectScope
80+
: vm
81+
? vm._scope
82+
: undefined
83+
)
7584
if ((this.vm = vm) && isRenderWatcher) {
7685
vm._watcher = this
7786
}

‎src/v3/reactivity/effectScope.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ export class EffectScope {
2727
* @internal
2828
*/
2929
scopes: EffectScope[] | undefined
30+
/**
31+
* indicates this being a component root scope
32+
* @internal
33+
*/
34+
_vm?: boolean
3035
/**
3136
* track a child scope's index in its parent's scopes array for optimized
3237
* removal
33-
* @internal
3438
*/
3539
private index: number | undefined
3640

0 commit comments

Comments
 (0)
Please sign in to comment.