File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 6
6
TrackOpTypes ,
7
7
TriggerOpTypes ,
8
8
DebuggerEvent ,
9
- markNonReactive
9
+ markNonReactive ,
10
+ ref
10
11
} from '../src/index'
11
12
import { ITERATE_KEY } from '../src/effect'
12
13
@@ -735,4 +736,14 @@ describe('reactivity/effect', () => {
735
736
obj . foo = NaN
736
737
expect ( fnSpy ) . toHaveBeenCalledTimes ( 1 )
737
738
} )
739
+
740
+ it ( 'should handle self dependency mutations' , ( ) => {
741
+ const count = ref ( 0 )
742
+ effect ( ( ) => {
743
+ count . value ++
744
+ } )
745
+ expect ( count . value ) . toBe ( 1 )
746
+ count . value = 10
747
+ expect ( count . value ) . toBe ( 11 )
748
+ } )
738
749
} )
Original file line number Diff line number Diff line change @@ -210,10 +210,16 @@ function addRunners(
210
210
) {
211
211
if ( effectsToAdd !== void 0 ) {
212
212
effectsToAdd . forEach ( effect => {
213
- if ( effect . options . computed ) {
214
- computedRunners . add ( effect )
213
+ if ( effect !== activeEffect ) {
214
+ if ( effect . options . computed ) {
215
+ computedRunners . add ( effect )
216
+ } else {
217
+ effects . add ( effect )
218
+ }
215
219
} else {
216
- effects . add ( effect )
220
+ // the effect mutated its own dependency during its execution.
221
+ // this can be caused by operations like foo.value++
222
+ // do not trigger or we end in an infinite loop
217
223
}
218
224
} )
219
225
}
You can’t perform that action at this time.
0 commit comments