Skip to content

Commit

Permalink
fix(runtime-core): should pause tracking when initializing legacy opt…
Browse files Browse the repository at this point in the history
…ions (#2524)

fix #2521
  • Loading branch information
HcySunYang authored Nov 27, 2020
1 parent 5b62662 commit 0ff2a4f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/runtime-core/__tests__/rendererComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,47 @@ describe('renderer: component', () => {
await nextTick()
expect(serializeInner(root)).toBe(`<div>1</div><div>1</div>`)
})

// #2521
test('should pause tracking deps when initializing legacy options', async () => {
let childInstance = null as any
const Child = {
props: ['foo'],
data() {
return {
count: 0
}
},
watch: {
foo: {
immediate: true,
handler() {
;(this as any).count
}
}
},
created() {
childInstance = this as any
childInstance.count
},
render() {
return h('h1', (this as any).count)
}
}

const App = {
setup() {
return () => h(Child)
},
updated: jest.fn()
}

const root = nodeOps.createElement('div')
render(h(App), root)
expect(App.updated).toHaveBeenCalledTimes(0)

childInstance.count++
await nextTick()
expect(App.updated).toHaveBeenCalledTimes(0)
})
})
2 changes: 2 additions & 0 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,9 @@ function finishComponentSetup(
// support for 2.x options
if (__FEATURE_OPTIONS_API__) {
currentInstance = instance
pauseTracking()
applyOptions(instance, Component)
resetTracking()
currentInstance = null
}

Expand Down

0 comments on commit 0ff2a4f

Please sign in to comment.