From: Tycho Date: Mon, 16 Sep 2024 02:28:46 +0000 (+0800) Subject: fix(reactivity): rely on dirty check only when computed has deps (#11931) X-Git-Tag: v3.5.6~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa5dafd2b55d42d6a29316a3bc91aea85c676a0b;p=thirdparty%2Fvuejs%2Fcore.git fix(reactivity): rely on dirty check only when computed has deps (#11931) close #11929 --- diff --git a/packages/reactivity/__tests__/computed.spec.ts b/packages/reactivity/__tests__/computed.spec.ts index e0b47cf56e..543c9c6e77 100644 --- a/packages/reactivity/__tests__/computed.spec.ts +++ b/packages/reactivity/__tests__/computed.spec.ts @@ -23,6 +23,7 @@ import { ref, shallowRef, toRaw, + triggerRef, } from '../src' import { EffectFlags, pauseTracking, resetTracking } from '../src/effect' import type { ComputedRef, ComputedRefImpl } from '../src/computed' @@ -1004,4 +1005,10 @@ describe('reactivity/computed', () => { await nextTick() expect(serializeInner(root)).toBe(`

Step 2

`) }) + + it('manual trigger computed', () => { + const cValue = computed(() => 1) + triggerRef(cValue) + expect(cValue.value).toBe(1) + }) }) diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index 8d323288b6..2dae285d16 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -352,7 +352,12 @@ export function refreshComputed(computed: ComputedRefImpl): undefined { // and therefore tracks no deps, thus we cannot rely on the dirty check. // Instead, computed always re-evaluate and relies on the globalVersion // fast path above for caching. - if (dep.version > 0 && !computed.isSSR && !isDirty(computed)) { + if ( + dep.version > 0 && + !computed.isSSR && + computed.deps && + !isDirty(computed) + ) { computed.flags &= ~EffectFlags.RUNNING return }