Open
Description
Vue version
3.3.8
Minimal reproduction
This test fails:
import { nextTick } from 'vue'
test('triggerRef with watch', async () => {
const a = shallowRef(1)
let aTriggered = false
watch(() => a.value, () => {
aTriggered = true
})
triggerRef(a)
await nextTick()
expect(aTriggered).toBe(true)
})
What is expected?
Watching values of manually triggered references should execute the watch callback.
What is actually happening?
Watching the ref
itself works fine. According to post by @LinusBorg in #1209 (comment), this is the expected design of Vue.
However, getting value
of the ref
does not work. So watch(() => a.value, ...)
won't work but, watch(a, ...)
work. The behavior should be the same and consistent for shallowRef
s where state tracking is disabled
watchEffect
works fine for these .value
calls. This is another undocumented inconsistency with watch
.
Official Vue docs state nothing about caching for watch
.