Skip to content

Commit 0ff2a4f

Browse files
authored
fix(runtime-core): should pause tracking when initializing legacy options (#2524)
fix #2521
1 parent 5b62662 commit 0ff2a4f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

packages/runtime-core/__tests__/rendererComponent.spec.ts

+43
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,47 @@ describe('renderer: component', () => {
232232
await nextTick()
233233
expect(serializeInner(root)).toBe(`<div>1</div><div>1</div>`)
234234
})
235+
236+
// #2521
237+
test('should pause tracking deps when initializing legacy options', async () => {
238+
let childInstance = null as any
239+
const Child = {
240+
props: ['foo'],
241+
data() {
242+
return {
243+
count: 0
244+
}
245+
},
246+
watch: {
247+
foo: {
248+
immediate: true,
249+
handler() {
250+
;(this as any).count
251+
}
252+
}
253+
},
254+
created() {
255+
childInstance = this as any
256+
childInstance.count
257+
},
258+
render() {
259+
return h('h1', (this as any).count)
260+
}
261+
}
262+
263+
const App = {
264+
setup() {
265+
return () => h(Child)
266+
},
267+
updated: jest.fn()
268+
}
269+
270+
const root = nodeOps.createElement('div')
271+
render(h(App), root)
272+
expect(App.updated).toHaveBeenCalledTimes(0)
273+
274+
childInstance.count++
275+
await nextTick()
276+
expect(App.updated).toHaveBeenCalledTimes(0)
277+
})
235278
})

packages/runtime-core/src/component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,9 @@ function finishComponentSetup(
704704
// support for 2.x options
705705
if (__FEATURE_OPTIONS_API__) {
706706
currentInstance = instance
707+
pauseTracking()
707708
applyOptions(instance, Component)
709+
resetTracking()
708710
currentInstance = null
709711
}
710712

0 commit comments

Comments
 (0)