-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Open
Labels
need guidanceThe approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.scope: reactivity
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 shallowRefs 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.
Metadata
Metadata
Assignees
Labels
need guidanceThe approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.scope: reactivity