Vue-next: watch handler not executed immediately if source returns undefined

Created on 1 Feb 2020  路  1Comment  路  Source: vuejs/vue-next

Version

3.0.0-alpha.4

Reproduction link

https://codepen.io/jkarczm/pen/ZEYgEXd?editors=0011

Steps to reproduce

watch(() => null, () => console.log('null watched'))
watch(() => undefined, () => console.log('undefined watched'))

What is expected?

null watched and undefined watched in console

What is actually happening?

only null watched in console

bug

Most helpful comment

https://github.com/vuejs/vue-next/blob/74cb207c2296c9865ba42e1539077f4bb68929f0/packages/runtime-core/src/apiWatch.ts#L156-L164

Seems to be caused by setting oldValue before first run to undefined, then checking against the result of the getter which is also undefined so no runs will take place until the value is changed.

>All comments

https://github.com/vuejs/vue-next/blob/74cb207c2296c9865ba42e1539077f4bb68929f0/packages/runtime-core/src/apiWatch.ts#L156-L164

Seems to be caused by setting oldValue before first run to undefined, then checking against the result of the getter which is also undefined so no runs will take place until the value is changed.

Was this page helpful?
0 / 5 - 0 ratings