Skip to content
Closed
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
22 changes: 22 additions & 0 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 @@ -481,4 +482,25 @@ describe('reactivity/computed', () => {
expect(provider.effect._dirtyLevel).toBe(DirtyLevels.Dirty)
expect(provider.value).toBe('1foo')
})

it('should be not dirty after deps mutate (mutate deps in computed)', async () => {
const state = reactive<any>({})
const consumer = computed(() => {
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: 5 additions & 0 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export class ComputedRefImpl<T> {
this.effect = new ReactiveEffect(
() => getter(this._value),
() => triggerRefValue(this, DirtyLevels.MaybeDirty),
() => {
if (this.effect._dirtyLevel >= DirtyLevels.Dirty) {
triggerRefValue(this, DirtyLevels.MaybeDirty)
}
},
)
this.effect.computed = this
this.effect.active = this._cacheable = !isSSR
Expand Down