fix(reactivity): effect should handle self dependency mutations
This commit is contained in:
parent
e1c9153b9e
commit
e8e67729cb
@ -6,7 +6,8 @@ import {
|
||||
TrackOpTypes,
|
||||
TriggerOpTypes,
|
||||
DebuggerEvent,
|
||||
markNonReactive
|
||||
markNonReactive,
|
||||
ref
|
||||
} from '../src/index'
|
||||
import { ITERATE_KEY } from '../src/effect'
|
||||
|
||||
@ -735,4 +736,14 @@ describe('reactivity/effect', () => {
|
||||
obj.foo = NaN
|
||||
expect(fnSpy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should handle self dependency mutations', () => {
|
||||
const count = ref(0)
|
||||
effect(() => {
|
||||
count.value++
|
||||
})
|
||||
expect(count.value).toBe(1)
|
||||
count.value = 10
|
||||
expect(count.value).toBe(11)
|
||||
})
|
||||
})
|
||||
|
@ -210,11 +210,17 @@ function addRunners(
|
||||
) {
|
||||
if (effectsToAdd !== void 0) {
|
||||
effectsToAdd.forEach(effect => {
|
||||
if (effect !== activeEffect) {
|
||||
if (effect.options.computed) {
|
||||
computedRunners.add(effect)
|
||||
} else {
|
||||
effects.add(effect)
|
||||
}
|
||||
} else {
|
||||
// the effect mutated its own dependency during its execution.
|
||||
// this can be caused by operations like foo.value++
|
||||
// do not trigger or we end in an infinite loop
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user