fix: ensure render watcher of manually created instance is correctly tracked in owner scope

fix #12701
This commit is contained in:
Evan You 2022-08-15 15:37:13 +08:00
parent 4b37b568c7
commit bd89ce53a9
2 changed files with 4 additions and 4 deletions

View File

@ -209,6 +209,7 @@ export function mountComponent(
// we set this to vm._watcher inside the watcher's constructor
// since the watcher's initial patch may call $forceUpdate (e.g. inside child
// component's mounted hook), which relies on vm._watcher being already defined
vm._scope.on()
new Watcher(
vm,
updateComponent,
@ -216,6 +217,7 @@ export function mountComponent(
watcherOptions,
true /* isRenderWatcher */
)
vm._scope.off()
hydrating = false
// flush buffer for flush: "pre" watchers queued in setup()

View File

@ -72,10 +72,8 @@ export default class Watcher implements DepTarget {
isRenderWatcher?: boolean
) {
recordEffectScope(this, activeEffectScope || (vm ? vm._scope : undefined))
if ((this.vm = vm)) {
if (isRenderWatcher) {
vm._watcher = this
}
if ((this.vm = vm) && isRenderWatcher) {
vm._watcher = this
}
// options
if (options) {