Skip to content

Commit aa5dafd

Browse files
authoredSep 16, 2024··
fix(reactivity): rely on dirty check only when computed has deps (#11931)
close #11929
1 parent 346bfaf commit aa5dafd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎packages/reactivity/__tests__/computed.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
ref,
2424
shallowRef,
2525
toRaw,
26+
triggerRef,
2627
} from '../src'
2728
import { EffectFlags, pauseTracking, resetTracking } from '../src/effect'
2829
import type { ComputedRef, ComputedRefImpl } from '../src/computed'
@@ -1004,4 +1005,10 @@ describe('reactivity/computed', () => {
10041005
await nextTick()
10051006
expect(serializeInner(root)).toBe(`<button>Step</button><p>Step 2</p>`)
10061007
})
1008+
1009+
it('manual trigger computed', () => {
1010+
const cValue = computed(() => 1)
1011+
triggerRef(cValue)
1012+
expect(cValue.value).toBe(1)
1013+
})
10071014
})

‎packages/reactivity/src/effect.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,12 @@ export function refreshComputed(computed: ComputedRefImpl): undefined {
352352
// and therefore tracks no deps, thus we cannot rely on the dirty check.
353353
// Instead, computed always re-evaluate and relies on the globalVersion
354354
// fast path above for caching.
355-
if (dep.version > 0 && !computed.isSSR && !isDirty(computed)) {
355+
if (
356+
dep.version > 0 &&
357+
!computed.isSSR &&
358+
computed.deps &&
359+
!isDirty(computed)
360+
) {
356361
computed.flags &= ~EffectFlags.RUNNING
357362
return
358363
}

0 commit comments

Comments
 (0)
Please sign in to comment.