mirror of https://github.com/vuejs/core.git
fix(watch): update `oldValue` before running `cb` to prevent stale value (#12296)
close #12294
This commit is contained in:
parent
1a664749d4
commit
c69c4bb59c
|
@ -277,4 +277,16 @@ describe('watch', () => {
|
|||
|
||||
expect(dummy).toEqual([1, 2, 3])
|
||||
})
|
||||
|
||||
test('watch with immediate reset and sync flush', () => {
|
||||
const value = ref(false)
|
||||
|
||||
watch(value, () => {
|
||||
value.value = false
|
||||
})
|
||||
|
||||
value.value = true
|
||||
value.value = true
|
||||
expect(value.value).toBe(false)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -264,11 +264,11 @@ export function watch(
|
|||
: oldValue,
|
||||
boundCleanup,
|
||||
]
|
||||
oldValue = newValue
|
||||
call
|
||||
? call(cb!, WatchErrorCodes.WATCH_CALLBACK, args)
|
||||
: // @ts-expect-error
|
||||
cb!(...args)
|
||||
oldValue = newValue
|
||||
} finally {
|
||||
activeWatcher = currentWatcher
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue