Skip to content

Commit 8d04205

Browse files
authoredJan 12, 2024
fix(reactivity): correct dirty assign in render function (#10091)
close #10082
1 parent 08b60f5 commit 8d04205

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
 

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

+32
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ import {
33
type ReactiveEffectRunner,
44
TrackOpTypes,
55
TriggerOpTypes,
6+
computed,
67
effect,
78
markRaw,
89
reactive,
910
readonly,
11+
ref,
1012
shallowReactive,
1113
stop,
1214
toRaw,
1315
} from '../src/index'
1416
import { pauseScheduling, resetScheduling } from '../src/effect'
1517
import { ITERATE_KEY, getDepFromReactive } from '../src/reactiveEffect'
18+
import { h, nextTick, nodeOps, render, serialize } from '@vue/runtime-test'
1619

1720
describe('reactivity/effect', () => {
1821
it('should run the passed function once (wrapped by a effect)', () => {
@@ -1011,6 +1014,35 @@ describe('reactivity/effect', () => {
10111014
expect(counterSpy).toHaveBeenCalledTimes(1)
10121015
})
10131016

1017+
// #10082
1018+
it('should set dirtyLevel when effect is allowRecurse and is running', async () => {
1019+
const s = ref(0)
1020+
const n = computed(() => s.value + 1)
1021+
1022+
const Child = {
1023+
setup() {
1024+
s.value++
1025+
return () => n.value
1026+
},
1027+
}
1028+
1029+
const renderSpy = vi.fn()
1030+
const Parent = {
1031+
setup() {
1032+
return () => {
1033+
renderSpy()
1034+
return [n.value, h(Child)]
1035+
}
1036+
},
1037+
}
1038+
1039+
const root = nodeOps.createElement('div')
1040+
render(h(Parent), root)
1041+
await nextTick()
1042+
expect(serialize(root)).toBe('<div>22</div>')
1043+
expect(renderSpy).toHaveBeenCalledTimes(2)
1044+
})
1045+
10141046
describe('empty dep cleanup', () => {
10151047
it('should remove the dep when the effect is stopped', () => {
10161048
const obj = reactive({ prop: 1 })

‎packages/reactivity/src/effect.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ export function triggerEffects(
295295
}
296296
if (
297297
effect._dirtyLevel < dirtyLevel &&
298-
(!effect._runnings || dirtyLevel !== DirtyLevels.ComputedValueDirty)
298+
(!effect._runnings ||
299+
effect.allowRecurse ||
300+
dirtyLevel !== DirtyLevels.ComputedValueDirty)
299301
) {
300302
const lastDirtyLevel = effect._dirtyLevel
301303
effect._dirtyLevel = dirtyLevel

0 commit comments

Comments
 (0)
Please sign in to comment.