File tree 2 files changed +28
-3
lines changed
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 4
4
WatchErrorCodes ,
5
5
type WatchOptions ,
6
6
type WatchScheduler ,
7
+ computed ,
7
8
onWatcherCleanup ,
8
9
ref ,
9
10
watch ,
@@ -209,4 +210,23 @@ describe('watch', () => {
209
210
source . value ++
210
211
expect ( dummy ) . toBe ( 1 )
211
212
} )
213
+
214
+ // #12033
215
+ test ( 'recursive sync watcher on computed' , ( ) => {
216
+ const r = ref ( 0 )
217
+ const c = computed ( ( ) => r . value )
218
+
219
+ watch ( c , v => {
220
+ if ( v > 1 ) {
221
+ r . value --
222
+ }
223
+ } )
224
+
225
+ expect ( r . value ) . toBe ( 0 )
226
+ expect ( c . value ) . toBe ( 0 )
227
+
228
+ r . value = 10
229
+ expect ( r . value ) . toBe ( 1 )
230
+ expect ( c . value ) . toBe ( 1 )
231
+ } )
212
232
} )
Original file line number Diff line number Diff line change @@ -260,11 +260,14 @@ export function endBatch(): void {
260
260
let error : unknown
261
261
while ( batchedSub ) {
262
262
let e : Subscriber | undefined = batchedSub
263
- batchedSub = undefined
263
+ let next : Subscriber | undefined
264
264
while ( e ) {
265
- const next : Subscriber | undefined = e . next
266
- e . next = undefined
267
265
e . flags &= ~ EffectFlags . NOTIFIED
266
+ e = e . next
267
+ }
268
+ e = batchedSub
269
+ batchedSub = undefined
270
+ while ( e ) {
268
271
if ( e . flags & EffectFlags . ACTIVE ) {
269
272
try {
270
273
// ACTIVE flag is effect-only
@@ -273,6 +276,8 @@ export function endBatch(): void {
273
276
if ( ! error ) error = err
274
277
}
275
278
}
279
+ next = e . next
280
+ e . next = undefined
276
281
e = next
277
282
}
278
283
}
You can’t perform that action at this time.
0 commit comments