Skip to content

Commit

Permalink
fix: ensure render watcher of manually created instance is correctly …
Browse files Browse the repository at this point in the history
…tracked in owner scope

fix #12701
  • Loading branch information
yyx990803 committed Aug 15, 2022
1 parent 4b37b56 commit bd89ce5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/core/instance/lifecycle.ts
Expand Up @@ -209,13 +209,15 @@ 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,
noop,
watcherOptions,
true /* isRenderWatcher */
)
vm._scope.off()
hydrating = false

// flush buffer for flush: "pre" watchers queued in setup()
Expand Down
6 changes: 2 additions & 4 deletions src/core/observer/watcher.ts
Expand Up @@ -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) {
Expand Down

0 comments on commit bd89ce5

Please sign in to comment.