Skip to content

Commit

Permalink
Revert "fix(reactivity): fix side effect computed dirty level (#11183)"
Browse files Browse the repository at this point in the history
This reverts commit 3bd79e3.
  • Loading branch information
yyx990803 committed Jun 28, 2024
1 parent 261fb7c commit 6c303ea
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 65 deletions.
57 changes: 0 additions & 57 deletions packages/reactivity/__tests__/computed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,63 +708,6 @@ describe('reactivity/computed', () => {
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
})

it('should chained computeds keep reactivity when computed effect happens', async () => {
const v = ref('Hello')
const c = computed(() => {
v.value += ' World'
return v.value
})
const d = computed(() => c.value)
const e = computed(() => d.value)
const Comp = {
setup: () => {
return () => d.value + ' | ' + e.value
},
}
const root = nodeOps.createElement('div')

render(h(Comp), root)
await nextTick()
expect(serializeInner(root)).toBe('Hello World | Hello World')

v.value += ' World'
await nextTick()
expect(serializeInner(root)).toBe(
'Hello World World World | Hello World World World',
)
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
})

it('should keep dirty level when side effect computed value changed', () => {
const v = ref(0)
const c = computed(() => {
v.value += 1
return v.value
})
const d = computed(() => {
return { d: c.value }
})

const Comp = {
setup: () => {
return () => {
return [d.value.d, d.value.d]
}
},
}

const root = nodeOps.createElement('div')
render(h(Comp), root)

expect(d.value.d).toBe(1)
expect(serializeInner(root)).toBe('11')
expect(c.effect._dirtyLevel).toBe(
DirtyLevels.MaybeDirty_ComputedSideEffect_Origin,
)
expect(d.effect._dirtyLevel).toBe(DirtyLevels.MaybeDirty_ComputedSideEffect)
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
})

it('debug: onTrigger (ref)', () => {
let events: DebuggerEvent[] = []
const onTrigger = vi.fn((e: DebuggerEvent) => {
Expand Down
6 changes: 1 addition & 5 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,11 @@ export class ComputedRefImpl<T> {
get value() {
// the computed ref may get wrapped by other proxies e.g. readonly() #3376
const self = toRaw(this)
const lastDirtyLevel = self.effect._dirtyLevel
if (
(!self._cacheable || self.effect.dirty) &&
hasChanged(self._value, (self._value = self.effect.run()!))
) {
// keep dirty level when side effect computed's value changed
if (lastDirtyLevel !== DirtyLevels.MaybeDirty_ComputedSideEffect) {
triggerRefValue(self, DirtyLevels.Dirty)
}
triggerRefValue(self, DirtyLevels.Dirty)
}
trackRefValue(self)
if (
Expand Down
4 changes: 1 addition & 3 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ export class ReactiveEffect<T = any> {
if (
dep.computed.effect._dirtyLevel ===
DirtyLevels.MaybeDirty_ComputedSideEffect_Origin
) {
resetTracking()
)
return true
}
triggerComputed(dep.computed)
if (this._dirtyLevel >= DirtyLevels.Dirty) {
break
Expand Down

0 comments on commit 6c303ea

Please sign in to comment.