fix(watch): pre-flush watcher watching props should trigger before component update
fix #1763
This commit is contained in:
@@ -432,6 +432,46 @@ describe('api: watch', () => {
|
||||
expect(cb).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
// #1763
|
||||
it('flush: pre watcher watching props should fire before child update', async () => {
|
||||
const a = ref(0)
|
||||
const b = ref(0)
|
||||
const calls: string[] = []
|
||||
|
||||
const Comp = {
|
||||
props: ['a', 'b'],
|
||||
setup(props: any) {
|
||||
watch(
|
||||
() => props.a + props.b,
|
||||
() => {
|
||||
calls.push('watcher')
|
||||
},
|
||||
{ flush: 'pre' }
|
||||
)
|
||||
return () => {
|
||||
calls.push('render')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const App = {
|
||||
render() {
|
||||
return h(Comp, { a: a.value, b: b.value })
|
||||
}
|
||||
}
|
||||
|
||||
render(h(App), nodeOps.createElement('div'))
|
||||
expect(calls).toEqual(['render'])
|
||||
|
||||
// both props are updated
|
||||
// should trigger pre-flush watcher first and only once
|
||||
// then trigger child render
|
||||
a.value++
|
||||
b.value++
|
||||
await nextTick()
|
||||
expect(calls).toEqual(['render', 'watcher', 'render'])
|
||||
})
|
||||
|
||||
it('deep', async () => {
|
||||
const state = reactive({
|
||||
nested: {
|
||||
|
||||
Reference in New Issue
Block a user