Skip to content

Commit 7768d43

Browse files
johnsoncodehkyyx990803
authored andcommitted
fix: avoid track unrelated effects
1 parent 0e0c44e commit 7768d43

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/reactivity/src/computed.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { DebuggerOptions, ReactiveEffect } from './effect'
1+
import {
2+
DebuggerOptions,
3+
pauseTracking,
4+
ReactiveEffect,
5+
resetTracking
6+
} from './effect'
27
import { Ref, trackRefValue, triggerRefValue } from './ref'
38
import { hasChanged, isFunction, NOOP } from '@vue/shared'
49
import { ReactiveFlags, toRaw } from './reactive'
@@ -65,19 +70,21 @@ export class ComputedRefImpl<T> {
6570
get value() {
6671
// the computed ref may get wrapped by other proxies e.g. readonly() #3376
6772
const self = toRaw(this)
68-
if (!self._dirty) {
73+
if (!self._dirty && self._computedsToAskDirty.length) {
74+
pauseTracking()
6975
for (const computedToAskDirty of self._computedsToAskDirty) {
7076
computedToAskDirty.value
7177
if (self._dirty) {
7278
break
7379
}
7480
}
81+
resetTracking()
7582
}
7683
trackRefValue(self)
7784
if (self._dirty || !self._cacheable) {
7885
const newValue = self.effect.run()!
7986
if (hasChanged(self._value, newValue)) {
80-
triggerRefValue(this, undefined)
87+
triggerRefValue(self, undefined)
8188
}
8289
self._value = newValue
8390
self._dirty = false

0 commit comments

Comments
 (0)