]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): rely on dirty check only when computed has deps (#11931)
authorTycho <jh.leong@outlook.com>
Mon, 16 Sep 2024 02:28:46 +0000 (10:28 +0800)
committerGitHub <noreply@github.com>
Mon, 16 Sep 2024 02:28:46 +0000 (10:28 +0800)
close #11929

packages/reactivity/__tests__/computed.spec.ts
packages/reactivity/src/effect.ts

index e0b47cf56ebbd2e804202b1cbfbce71f0f85114f..543c9c6e770e5c286492e7fee5df6913a82722e8 100644 (file)
@@ -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(`<button>Step</button><p>Step 2</p>`)
   })
+
+  it('manual trigger computed', () => {
+    const cValue = computed(() => 1)
+    triggerRef(cValue)
+    expect(cValue.value).toBe(1)
+  })
 })
index 8d323288b6c36f8c8ca7a0e3866041f93846fa9c..2dae285d1665be96bcdd14702fcefdd618da0e59 100644 (file)
@@ -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
   }