Skip to content

Commit 20f62af

Browse files
authored
fix(reactivity): fix regression for computed with mutation (#10119)
close #10114
1 parent 3cd3a44 commit 20f62af

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

packages/reactivity/__tests__/computed.spec.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { h, nextTick, nodeOps, render, serializeInner } from '@vue/runtime-test'
12
import {
23
type DebuggerEvent,
34
ITERATE_KEY,
@@ -470,15 +471,24 @@ describe('reactivity/computed', () => {
470471
expect(c2.effect._dirtyLevel).toBe(DirtyLevels.NotDirty)
471472
})
472473

473-
it('should work when chained(ref+computed)', () => {
474-
const value = ref(0)
474+
it('should be not dirty after deps mutate (mutate deps in computed)', async () => {
475+
const state = reactive<any>({})
475476
const consumer = computed(() => {
476-
value.value++
477-
return 'foo'
478-
})
479-
const provider = computed(() => value.value + consumer.value)
480-
expect(provider.value).toBe('0foo')
481-
expect(provider.effect._dirtyLevel).toBe(DirtyLevels.Dirty)
482-
expect(provider.value).toBe('1foo')
477+
if (!('a' in state)) state.a = 1
478+
return state.a
479+
})
480+
const Comp = {
481+
setup: () => {
482+
nextTick().then(() => {
483+
state.a = 2
484+
})
485+
return () => consumer.value
486+
},
487+
}
488+
const root = nodeOps.createElement('div')
489+
render(h(Comp), root)
490+
await nextTick()
491+
await nextTick()
492+
expect(serializeInner(root)).toBe(`2`)
483493
})
484494
})

packages/reactivity/src/effect.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ export function triggerEffects(
295295
// when recurse effect is running, dep map could have outdated items
296296
continue
297297
}
298-
if (effect._dirtyLevel < dirtyLevel) {
298+
if (
299+
effect._dirtyLevel < dirtyLevel &&
300+
!(effect._runnings && !effect.allowRecurse)
301+
) {
299302
const lastDirtyLevel = effect._dirtyLevel
300303
effect._dirtyLevel = dirtyLevel
301304
if (lastDirtyLevel === DirtyLevels.NotDirty) {

0 commit comments

Comments
 (0)