@@ -508,12 +508,10 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
508508 }
509509
510510 function performSynchronousWork ( ) {
511- if ( useSyncScheduling ) {
512- // Start batching updates
513- shouldBatchUpdates = true ;
514- }
515- performAndHandleErrors ( performSynchronousWorkUnsafe ) ;
516- shouldBatchUpdates = false ;
511+ // All nested updates are batched
512+ batchedUpdates ( ( ) => {
513+ performAndHandleErrors ( performSynchronousWorkUnsafe ) ;
514+ } ) ;
517515 }
518516
519517 function scheduleSynchronousWork ( root : FiberRoot ) {
@@ -534,6 +532,7 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
534532 lastScheduledRoot = root ;
535533
536534 if ( ! shouldBatchUpdates ) {
535+ // Unless in batched mode, perform work immediately
537536 performSynchronousWork ( ) ;
538537 }
539538 }
@@ -690,9 +689,20 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
690689 }
691690 }
692691
692+ function batchedUpdates ( fn : Function ) {
693+ const prev = shouldBatchUpdates ;
694+ shouldBatchUpdates = true ;
695+ try {
696+ fn ( ) ;
697+ } finally {
698+ shouldBatchUpdates = prev ;
699+ }
700+ }
701+
693702 return {
694703 scheduleWork : scheduleWork ,
695704 scheduleDeferredWork : scheduleDeferredWork ,
696705 performWithPriority : performWithPriority ,
706+ batchedUpdates : batchedUpdates ,
697707 } ;
698708} ;
0 commit comments