fix(runtime-core): ensure watchers are always registered to correct instance owner (#2495)

close: #2381
This commit is contained in:
Thorsten Lünborg
2020-11-27 15:31:50 +01:00
committed by GitHub
parent ce4915d8be
commit 735af1c7b7
3 changed files with 68 additions and 7 deletions

View File

@@ -285,7 +285,7 @@ function doWatch(
scheduler
})
recordInstanceBoundEffect(runner)
recordInstanceBoundEffect(runner, instance)
// initial run
if (cb) {

View File

@@ -786,9 +786,12 @@ export function createSetupContext(
// record effects created during a component's setup() so that they can be
// stopped when the component unmounts
export function recordInstanceBoundEffect(effect: ReactiveEffect) {
if (currentInstance) {
;(currentInstance.effects || (currentInstance.effects = [])).push(effect)
export function recordInstanceBoundEffect(
effect: ReactiveEffect,
instance = currentInstance
) {
if (instance) {
;(instance.effects || (instance.effects = [])).push(effect)
}
}