File tree 3 files changed +40
-3
lines changed
3 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -84,9 +84,13 @@ export class ComputedRefImpl<T = any> implements Subscriber {
84
84
* @internal
85
85
*/
86
86
isSSR : boolean
87
+ /**
88
+ * @internal
89
+ */
90
+ next ?: Subscriber = undefined
91
+
87
92
// for backwards compat
88
93
effect : this = this
89
-
90
94
// dev only
91
95
onTrack ?: ( event : DebuggerEvent ) => void
92
96
// dev only
Original file line number Diff line number Diff line change @@ -261,13 +261,20 @@ export function endBatch(): void {
261
261
while ( batchedSub ) {
262
262
let e : Subscriber | undefined = batchedSub
263
263
let next : Subscriber | undefined
264
+ // 1st pass: clear notified flags for computed upfront
265
+ // we use the ACTIVE flag as a discriminator between computed and effect,
266
+ // since NOTIFIED is useless for an inactive effect anyway.
264
267
while ( e ) {
265
- e . flags &= ~ EffectFlags . NOTIFIED
268
+ if ( ! ( e . flags & EffectFlags . ACTIVE ) ) {
269
+ e . flags &= ~ EffectFlags . NOTIFIED
270
+ }
266
271
e = e . next
267
272
}
268
273
e = batchedSub
269
274
batchedSub = undefined
275
+ // 2nd pass: run effects
270
276
while ( e ) {
277
+ e . flags &= ~ EffectFlags . NOTIFIED
271
278
if ( e . flags & EffectFlags . ACTIVE ) {
272
279
try {
273
280
// ACTIVE flag is effect-only
Original file line number Diff line number Diff line change @@ -1930,7 +1930,7 @@ describe('api: watch', () => {
1930
1930
warn . mockRestore ( )
1931
1931
} )
1932
1932
1933
- it ( 'should be executed correctly' , ( ) => {
1933
+ test ( 'should be executed correctly' , ( ) => {
1934
1934
const v = ref ( 1 )
1935
1935
let foo = ''
1936
1936
@@ -1957,4 +1957,30 @@ describe('api: watch', () => {
1957
1957
v . value ++
1958
1958
expect ( foo ) . toBe ( '12' )
1959
1959
} )
1960
+
1961
+ // 12045
1962
+ test ( 'sync watcher should not break pre watchers' , async ( ) => {
1963
+ const count1 = ref ( 0 )
1964
+ const count2 = ref ( 0 )
1965
+
1966
+ watch (
1967
+ count1 ,
1968
+ ( ) => {
1969
+ count2 . value ++
1970
+ } ,
1971
+ { flush : 'sync' } ,
1972
+ )
1973
+
1974
+ const spy1 = vi . fn ( )
1975
+ watch ( [ count1 , count2 ] , spy1 )
1976
+
1977
+ const spy2 = vi . fn ( )
1978
+ watch ( count1 , spy2 )
1979
+
1980
+ count1 . value ++
1981
+
1982
+ await nextTick ( )
1983
+ expect ( spy1 ) . toHaveBeenCalled ( )
1984
+ expect ( spy2 ) . toHaveBeenCalled ( )
1985
+ } )
1960
1986
} )
You can’t perform that action at this time.
0 commit comments