Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions packages/reactivity/__tests__/computed.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { h, nextTick, nodeOps, render, serializeInner } from '@vue/runtime-test'
import {
type DebuggerEvent,
ITERATE_KEY,
Expand Down Expand Up @@ -470,15 +471,24 @@ describe('reactivity/computed', () => {
expect(c2.effect._dirtyLevel).toBe(DirtyLevels.NotDirty)
})

it('should work when chained(ref+computed)', () => {
const value = ref(0)
it('should be not dirty after deps mutate (mutate deps in computed)', async () => {
const state = reactive<any>({})
const consumer = computed(() => {
value.value++
return 'foo'
})
const provider = computed(() => value.value + consumer.value)
expect(provider.value).toBe('0foo')
expect(provider.effect._dirtyLevel).toBe(DirtyLevels.Dirty)
expect(provider.value).toBe('1foo')
if (!('a' in state)) state.a = 1
return state.a
})
const Comp = {
setup: () => {
nextTick().then(() => {
state.a = 2
})
return () => consumer.value
},
}
const root = nodeOps.createElement('div')
render(h(Comp), root)
await nextTick()
await nextTick()
expect(serializeInner(root)).toBe(`2`)
})
})
5 changes: 4 additions & 1 deletion packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ export function triggerEffects(
// when recurse effect is running, dep map could have outdated items
continue
}
if (effect._dirtyLevel < dirtyLevel) {
if (
effect._dirtyLevel < dirtyLevel &&
!(effect._runnings && !effect.allowRecurse)
) {
const lastDirtyLevel = effect._dirtyLevel
effect._dirtyLevel = dirtyLevel
if (lastDirtyLevel === DirtyLevels.NotDirty) {
Expand Down