]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): correct dirty assign in render function (#10091)
authorDoctorwu <44631608+Doctor-wu@users.noreply.github.com>
Fri, 12 Jan 2024 13:13:17 +0000 (21:13 +0800)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2024 13:13:17 +0000 (21:13 +0800)
close #10082

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

index 9109177bf49a437abc824205e04738c53dd9f0bb..925d9ed61040788332009bc33e35b53b2ae26183 100644 (file)
@@ -3,16 +3,19 @@ import {
   type ReactiveEffectRunner,
   TrackOpTypes,
   TriggerOpTypes,
+  computed,
   effect,
   markRaw,
   reactive,
   readonly,
+  ref,
   shallowReactive,
   stop,
   toRaw,
 } from '../src/index'
 import { pauseScheduling, resetScheduling } from '../src/effect'
 import { ITERATE_KEY, getDepFromReactive } from '../src/reactiveEffect'
+import { h, nextTick, nodeOps, render, serialize } from '@vue/runtime-test'
 
 describe('reactivity/effect', () => {
   it('should run the passed function once (wrapped by a effect)', () => {
@@ -1011,6 +1014,35 @@ describe('reactivity/effect', () => {
     expect(counterSpy).toHaveBeenCalledTimes(1)
   })
 
+  // #10082
+  it('should set dirtyLevel when effect is allowRecurse and is running', async () => {
+    const s = ref(0)
+    const n = computed(() => s.value + 1)
+
+    const Child = {
+      setup() {
+        s.value++
+        return () => n.value
+      },
+    }
+
+    const renderSpy = vi.fn()
+    const Parent = {
+      setup() {
+        return () => {
+          renderSpy()
+          return [n.value, h(Child)]
+        }
+      },
+    }
+
+    const root = nodeOps.createElement('div')
+    render(h(Parent), root)
+    await nextTick()
+    expect(serialize(root)).toBe('<div>22</div>')
+    expect(renderSpy).toHaveBeenCalledTimes(2)
+  })
+
   describe('empty dep cleanup', () => {
     it('should remove the dep when the effect is stopped', () => {
       const obj = reactive({ prop: 1 })
index 5ddf8e6f0accfd1c576fe37043f03807f772bd0f..8876604bc7a3538322722259c962bf8400b75516 100644 (file)
@@ -295,7 +295,9 @@ export function triggerEffects(
     }
     if (
       effect._dirtyLevel < dirtyLevel &&
-      (!effect._runnings || dirtyLevel !== DirtyLevels.ComputedValueDirty)
+      (!effect._runnings ||
+        effect.allowRecurse ||
+        dirtyLevel !== DirtyLevels.ComputedValueDirty)
     ) {
       const lastDirtyLevel = effect._dirtyLevel
       effect._dirtyLevel = dirtyLevel