mirror of https://github.com/vuejs/core.git
fix(reactivity): fix recursive sync watcher on computed edge case
close #12033 close #12037
This commit is contained in:
parent
cb34b28a4a
commit
10ff159240
|
@ -4,6 +4,7 @@ import {
|
||||||
WatchErrorCodes,
|
WatchErrorCodes,
|
||||||
type WatchOptions,
|
type WatchOptions,
|
||||||
type WatchScheduler,
|
type WatchScheduler,
|
||||||
|
computed,
|
||||||
onWatcherCleanup,
|
onWatcherCleanup,
|
||||||
ref,
|
ref,
|
||||||
watch,
|
watch,
|
||||||
|
@ -209,4 +210,23 @@ describe('watch', () => {
|
||||||
source.value++
|
source.value++
|
||||||
expect(dummy).toBe(1)
|
expect(dummy).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #12033
|
||||||
|
test('recursive sync watcher on computed', () => {
|
||||||
|
const r = ref(0)
|
||||||
|
const c = computed(() => r.value)
|
||||||
|
|
||||||
|
watch(c, v => {
|
||||||
|
if (v > 1) {
|
||||||
|
r.value--
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(r.value).toBe(0)
|
||||||
|
expect(c.value).toBe(0)
|
||||||
|
|
||||||
|
r.value = 10
|
||||||
|
expect(r.value).toBe(1)
|
||||||
|
expect(c.value).toBe(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -260,11 +260,14 @@ export function endBatch(): void {
|
||||||
let error: unknown
|
let error: unknown
|
||||||
while (batchedSub) {
|
while (batchedSub) {
|
||||||
let e: Subscriber | undefined = batchedSub
|
let e: Subscriber | undefined = batchedSub
|
||||||
|
let next: Subscriber | undefined
|
||||||
|
while (e) {
|
||||||
|
e.flags &= ~EffectFlags.NOTIFIED
|
||||||
|
e = e.next
|
||||||
|
}
|
||||||
|
e = batchedSub
|
||||||
batchedSub = undefined
|
batchedSub = undefined
|
||||||
while (e) {
|
while (e) {
|
||||||
const next: Subscriber | undefined = e.next
|
|
||||||
e.next = undefined
|
|
||||||
e.flags &= ~EffectFlags.NOTIFIED
|
|
||||||
if (e.flags & EffectFlags.ACTIVE) {
|
if (e.flags & EffectFlags.ACTIVE) {
|
||||||
try {
|
try {
|
||||||
// ACTIVE flag is effect-only
|
// ACTIVE flag is effect-only
|
||||||
|
@ -273,6 +276,8 @@ export function endBatch(): void {
|
||||||
if (!error) error = err
|
if (!error) error = err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
next = e.next
|
||||||
|
e.next = undefined
|
||||||
e = next
|
e = next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue