]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix: Revert "fix(reactivity): self-referencing computed should refresh"
authorEvan You <evan@vuejs.org>
Fri, 6 Sep 2024 00:47:12 +0000 (08:47 +0800)
committerEvan You <evan@vuejs.org>
Fri, 6 Sep 2024 00:47:12 +0000 (08:47 +0800)
This reverts commit e84c4a608e9dc96fb2a4a29d538bcc64f26103a2.

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

index e0b47cf56ebbd2e804202b1cbfbce71f0f85114f..31daef559a8115a043efe3a8316d7f21f8561c63 100644 (file)
@@ -594,7 +594,7 @@ describe('reactivity/computed', () => {
 
     v.value += ' World'
     await nextTick()
-    expect(serializeInner(root)).toBe('Hello World World World World')
+    expect(serializeInner(root)).toBe('Hello World World World')
     // expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
   })
 
@@ -892,7 +892,7 @@ describe('reactivity/computed', () => {
     v.value += ' World'
     await nextTick()
     expect(serializeInner(root)).toBe(
-      'Hello World World World World | Hello World World World World',
+      'Hello World World World | Hello World World World',
     )
   })
 
@@ -962,7 +962,6 @@ describe('reactivity/computed', () => {
     })
   })
 
-  // #11797
   test('should prevent endless recursion in self-referencing computed getters', async () => {
     const Comp = defineComponent({
       data() {
@@ -999,7 +998,7 @@ describe('reactivity/computed', () => {
     })
     const root = nodeOps.createElement('div')
     render(h(Comp), root)
-    expect(serializeInner(root)).toBe(`<button>Step</button><p>Step 1</p>`)
+    expect(serializeInner(root)).toBe(`<button>Step</button><p></p>`)
     triggerEvent(root.children[1] as TestElement, 'click')
     await nextTick()
     expect(serializeInner(root)).toBe(`<button>Step</button><p>Step 2</p>`)
index d2dd67bf97c444da4b7a0e4c9ae57e4fc1ce8f2e..aa5d2079061f8d36caed72484ab628bd641c7c44 100644 (file)
@@ -111,9 +111,9 @@ export class ComputedRefImpl<T = any> implements Subscriber {
    * @internal
    */
   notify(): void {
-    this.flags |= EffectFlags.DIRTY
     // avoid infinite self recursion
     if (activeSub !== this) {
+      this.flags |= EffectFlags.DIRTY
       this.dep.notify()
     } else if (__DEV__) {
       // TODO warn
index 51df32e9969ad8e1759608d6fc8a9b3e12b73bfa..88493e4e9a9e015fa0994ebd2840f2218774c8b2 100644 (file)
@@ -345,6 +345,9 @@ function isDirty(sub: Subscriber): boolean {
  * @internal
  */
 export function refreshComputed(computed: ComputedRefImpl): false | undefined {
+  if (computed.flags & EffectFlags.RUNNING) {
+    return false
+  }
   if (
     computed.flags & EffectFlags.TRACKING &&
     !(computed.flags & EffectFlags.DIRTY)