Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): should pause tracking deps when initializing legacy options #2524

Merged
merged 1 commit into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -688,7 +688,9 @@ function finishComponentSetup(
// support for 2.x options
if (__FEATURE_OPTIONS_API__) {
currentInstance = instance
pauseTracking()
applyOptions(instance, Component)
resetTracking()
currentInstance = null
}

Expand Down