Skip to content

Commit e596378

Browse files
committedSep 10, 2024··
fix: Revert "fix: Revert "fix(reactivity): self-referencing computed should refresh""
This reverts commit 35c760f.
1 parent 48613bb commit e596378

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed
 

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ describe('reactivity/computed', () => {
594594

595595
v.value += ' World'
596596
await nextTick()
597-
expect(serializeInner(root)).toBe('Hello World World World')
597+
expect(serializeInner(root)).toBe('Hello World World World World')
598598
// expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
599599
})
600600

@@ -892,7 +892,7 @@ describe('reactivity/computed', () => {
892892
v.value += ' World'
893893
await nextTick()
894894
expect(serializeInner(root)).toBe(
895-
'Hello World World World | Hello World World World',
895+
'Hello World World World World | Hello World World World World',
896896
)
897897
})
898898

@@ -962,6 +962,7 @@ describe('reactivity/computed', () => {
962962
})
963963
})
964964

965+
// #11797
965966
test('should prevent endless recursion in self-referencing computed getters', async () => {
966967
const Comp = defineComponent({
967968
data() {
@@ -998,7 +999,7 @@ describe('reactivity/computed', () => {
998999
})
9991000
const root = nodeOps.createElement('div')
10001001
render(h(Comp), root)
1001-
expect(serializeInner(root)).toBe(`<button>Step</button><p></p>`)
1002+
expect(serializeInner(root)).toBe(`<button>Step</button><p>Step 1</p>`)
10021003
triggerEvent(root.children[1] as TestElement, 'click')
10031004
await nextTick()
10041005
expect(serializeInner(root)).toBe(`<button>Step</button><p>Step 2</p>`)

‎packages/reactivity/src/computed.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ export class ComputedRefImpl<T = any> implements Subscriber {
111111
* @internal
112112
*/
113113
notify(): void {
114+
this.flags |= EffectFlags.DIRTY
114115
// avoid infinite self recursion
115116
if (activeSub !== this) {
116-
this.flags |= EffectFlags.DIRTY
117117
this.dep.notify()
118118
} else if (__DEV__) {
119119
// TODO warn

‎packages/reactivity/src/effect.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function isDirty(sub: Subscriber): boolean {
326326
for (let link = sub.deps; link; link = link.nextDep) {
327327
if (
328328
link.dep.version !== link.version ||
329-
(link.dep.computed && refreshComputed(link.dep.computed) === false) ||
329+
(link.dep.computed && refreshComputed(link.dep.computed)) ||
Has conversations. Original line has conversations.
330330
link.dep.version !== link.version
331331
) {
332332
return true
@@ -344,10 +344,7 @@ function isDirty(sub: Subscriber): boolean {
344344
* Returning false indicates the refresh failed
345345
* @internal
346346
*/
347-
export function refreshComputed(computed: ComputedRefImpl): false | undefined {
348-
if (computed.flags & EffectFlags.RUNNING) {
349-
return false
350-
}
347+
export function refreshComputed(computed: ComputedRefImpl): undefined {
351348
if (
352349
computed.flags & EffectFlags.TRACKING &&
353350
!(computed.flags & EffectFlags.DIRTY)

0 commit comments

Comments
 (0)
Please sign in to comment.