Skip to content

Commit

Permalink
fix: avoid track unrelated effects
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk authored and yyx990803 committed Apr 5, 2023
1 parent 82eaeae commit 30a2d61
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { DebuggerOptions, ReactiveEffect } from './effect'
import {
DebuggerOptions,
pauseTracking,
ReactiveEffect,
resetTracking
} from './effect'
import { Ref, trackRefValue, triggerRefValue } from './ref'
import { hasChanged, isFunction, NOOP } from '@vue/shared'
import { ReactiveFlags, toRaw } from './reactive'
Expand Down Expand Up @@ -65,19 +70,21 @@ export class ComputedRefImpl<T> {
get value() {
// the computed ref may get wrapped by other proxies e.g. readonly() #3376
const self = toRaw(this)
if (!self._dirty) {
if (!self._dirty && self._computedsToAskDirty.length) {
pauseTracking()
for (const computedToAskDirty of self._computedsToAskDirty) {
computedToAskDirty.value
if (self._dirty) {
break
}
}
resetTracking()
}
trackRefValue(self)
if (self._dirty || !self._cacheable) {
const newValue = self.effect.run()!
if (hasChanged(self._value, newValue)) {
triggerRefValue(this, undefined)
triggerRefValue(self, undefined)
}
self._value = newValue
self._dirty = false
Expand Down

0 comments on commit 30a2d61

Please sign in to comment.