@@ -45,7 +45,6 @@ export type DebuggerEventExtraInfo = {
4545 oldTarget ?: Map < any , any > | Set < any >
4646}
4747
48- const effectStack : ReactiveEffect [ ] = [ ]
4948let activeEffect : ReactiveEffect | undefined
5049
5150export const ITERATE_KEY = Symbol ( __DEV__ ? 'iterate' : '' )
@@ -54,6 +53,7 @@ export const MAP_KEY_ITERATE_KEY = Symbol(__DEV__ ? 'Map key iterate' : '')
5453export class ReactiveEffect < T = any > {
5554 active = true
5655 deps : Dep [ ] = [ ]
56+ parent : ReactiveEffect | undefined = undefined
5757
5858 /**
5959 * Can be attached after creation
@@ -74,7 +74,7 @@ export class ReactiveEffect<T = any> {
7474 constructor (
7575 public fn : ( ) => T ,
7676 public scheduler : EffectScheduler | null = null ,
77- scope ?: EffectScope | null
77+ scope ?: EffectScope
7878 ) {
7979 recordEffectScope ( this , scope )
8080 }
@@ -83,31 +83,37 @@ export class ReactiveEffect<T = any> {
8383 if ( ! this . active ) {
8484 return this . fn ( )
8585 }
86- if ( ! effectStack . length || ! effectStack . includes ( this ) ) {
87- try {
88- effectStack . push ( ( activeEffect = this ) )
89- enableTracking ( )
86+ let parent : ReactiveEffect | undefined = activeEffect
87+ let lastShouldTrack = shouldTrack
88+ while ( parent ) {
89+ if ( parent === this ) {
90+ return
91+ }
92+ parent = parent . parent
93+ }
94+ try {
95+ this . parent = activeEffect
96+ activeEffect = this
97+ shouldTrack = true
9098
91- trackOpBit = 1 << ++ effectTrackDepth
99+ trackOpBit = 1 << ++ effectTrackDepth
92100
93- if ( effectTrackDepth <= maxMarkerBits ) {
94- initDepMarkers ( this )
95- } else {
96- cleanupEffect ( this )
97- }
98- return this . fn ( )
99- } finally {
100- if ( effectTrackDepth <= maxMarkerBits ) {
101- finalizeDepMarkers ( this )
102- }
101+ if ( effectTrackDepth <= maxMarkerBits ) {
102+ initDepMarkers ( this )
103+ } else {
104+ cleanupEffect ( this )
105+ }
106+ return this . fn ( )
107+ } finally {
108+ if ( effectTrackDepth <= maxMarkerBits ) {
109+ finalizeDepMarkers ( this )
110+ }
103111
104- trackOpBit = 1 << -- effectTrackDepth
112+ trackOpBit = 1 << -- effectTrackDepth
105113
106- resetTracking ( )
107- effectStack . pop ( )
108- const n = effectStack . length
109- activeEffect = n > 0 ? effectStack [ n - 1 ] : undefined
110- }
114+ activeEffect = this . parent
115+ shouldTrack = lastShouldTrack
116+ this . parent = undefined
111117 }
112118 }
113119
@@ -214,7 +220,7 @@ export function track(target: object, type: TrackOpTypes, key: unknown) {
214220}
215221
216222export function isTracking ( ) {
217- return shouldTrack && activeEffect !== undefined
223+ return shouldTrack && ! ! activeEffect
218224}
219225
220226export function trackEffects (
0 commit comments