Skip to content

Commit

Permalink
fix: Revert "fix(reactivity): self-referencing computed should refresh"
Browse files Browse the repository at this point in the history
This reverts commit e84c4a6.
  • Loading branch information
yyx990803 committed Sep 6, 2024
1 parent babfb4c commit 35c760f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
7 changes: 3 additions & 4 deletions packages/reactivity/__tests__/computed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down Expand Up @@ -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',
)
})

Expand Down Expand Up @@ -962,7 +962,6 @@ describe('reactivity/computed', () => {
})
})

// #11797
test('should prevent endless recursion in self-referencing computed getters', async () => {
const Comp = defineComponent({
data() {
Expand Down Expand Up @@ -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>`)
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 35c760f

Please sign in to comment.