@@ -167,7 +167,7 @@ import {
167
167
hasCaughtError ,
168
168
clearCaughtError ,
169
169
} from 'shared/ReactErrorUtils' ;
170
- import { onCommitRoot } from './ReactFiberDevToolsHook' ;
170
+ import { isDevToolsPresent , onCommitRoot } from './ReactFiberDevToolsHook' ;
171
171
172
172
const ceil = Math . ceil ;
173
173
@@ -339,13 +339,15 @@ export function scheduleUpdateOnFiber(
339
339
}
340
340
341
341
if ( enableUpdaterTracking ) {
342
- const pendingUpdatersMap = root . pendingUpdatersMap ;
343
- let updaters = pendingUpdatersMap . get ( expirationTime ) ;
344
- if ( updaters == null ) {
345
- updaters = new Set ( ) ;
346
- pendingUpdatersMap . set ( expirationTime , updaters ) ;
342
+ if ( isDevToolsPresent ) {
343
+ const pendingUpdatersMap = root . pendingUpdatersMap ;
344
+ let updaters = pendingUpdatersMap . get ( expirationTime ) ;
345
+ if ( updaters == null ) {
346
+ updaters = new Set ( ) ;
347
+ pendingUpdatersMap . set ( expirationTime , updaters ) ;
348
+ }
349
+ updaters . add ( fiber ) ;
347
350
}
348
- updaters . add ( fiber ) ;
349
351
}
350
352
351
353
root . pingTime = NoWork ;
@@ -813,6 +815,17 @@ function renderRoot(
813
815
Interaction ,
814
816
> ) ;
815
817
}
818
+
819
+ if ( enableUpdaterTracking ) {
820
+ if ( isDevToolsPresent ) {
821
+ // If we didn't finish the current work, restore pending updaters for the next pass.
822
+ if ( root . memoizedUpdaters . size > 0 ) {
823
+ restorePendingUpdaters ( root , expirationTime ) ;
824
+ root . memoizedUpdaters . clear ( ) ;
825
+ }
826
+ }
827
+ }
828
+
816
829
return renderRoot . bind ( null , root , currentTime ) ;
817
830
}
818
831
}
@@ -878,6 +891,17 @@ function renderRoot(
878
891
if ( expirationTime !== Sync ) {
879
892
startRequestCallbackTimer ( ) ;
880
893
}
894
+
895
+ if ( enableUpdaterTracking ) {
896
+ if ( isDevToolsPresent ) {
897
+ // If we didn't finish the current work, restore pending updaters for the next pass.
898
+ if ( root . memoizedUpdaters . size > 0 ) {
899
+ restorePendingUpdaters ( root , expirationTime ) ;
900
+ root . memoizedUpdaters . clear ( ) ;
901
+ }
902
+ }
903
+ }
904
+
881
905
return renderRoot . bind ( null , root , expirationTime ) ;
882
906
}
883
907
}
@@ -1305,8 +1329,10 @@ function commitRootImpl(root) {
1305
1329
root . lastPendingTime = firstPendingTimeBeforeCommit ;
1306
1330
1307
1331
if ( enableUpdaterTracking ) {
1308
- if ( firstPendingTimeBeforeCommit !== NoWork ) {
1309
- restorePendingUpdaters ( root , root . lastPendingTime ) ;
1332
+ if ( isDevToolsPresent ) {
1333
+ if ( firstPendingTimeBeforeCommit !== NoWork ) {
1334
+ restorePendingUpdaters ( root , root . lastPendingTime ) ;
1335
+ }
1310
1336
}
1311
1337
}
1312
1338
}
@@ -1515,6 +1541,12 @@ function commitRootImpl(root) {
1515
1541
1516
1542
onCommitRoot ( finishedWork . stateNode ) ;
1517
1543
1544
+ if ( enableUpdaterTracking ) {
1545
+ if ( isDevToolsPresent ) {
1546
+ root . memoizedUpdaters . clear ( ) ;
1547
+ }
1548
+ }
1549
+
1518
1550
if ( remainingExpirationTime === Sync ) {
1519
1551
// Count the number of times the root synchronously re-renders without
1520
1552
// finishing. If there are too many, it indicates an infinite update loop.
@@ -2191,7 +2223,7 @@ export function restorePendingUpdaters(
2191
2223
root : FiberRoot ,
2192
2224
expirationTime : ExpirationTime ,
2193
2225
) : void {
2194
- if ( ! enableUpdaterTracking ) {
2226
+ if ( ! enableUpdaterTracking || ! isDevToolsPresent ) {
2195
2227
return ;
2196
2228
}
2197
2229
const pendingUpdatersMap = root . pendingUpdatersMap ;
@@ -2323,20 +2355,21 @@ function startWorkOnPendingInteraction(root, expirationTime) {
2323
2355
// This is called when new work is started on a root.
2324
2356
2325
2357
if ( enableUpdaterTracking ) {
2326
- const memoizedUpdaters : Set < Fiber > = new Set();
2327
- const pendingUpdatersMap = root.pendingUpdatersMap;
2328
- pendingUpdatersMap.forEach((updaters, scheduledExpirationTime) => {
2329
- if ( scheduledExpirationTime >= expirationTime ) {
2330
- pendingUpdatersMap . delete ( scheduledExpirationTime ) ;
2331
- updaters . forEach ( fiber => memoizedUpdaters . add ( fiber ) ) ;
2332
- }
2333
- } ) ;
2334
-
2335
- // Store the current set of interactions on the FiberRoot for a few reasons:
2336
- // We can re-use it in hot functions like renderRoot() without having to
2337
- // recalculate it. This also provides DevTools with a way to access it when
2338
- // the onCommitRoot() hook is called.
2339
- root . memoizedUpdaters = memoizedUpdaters ;
2358
+ if ( isDevToolsPresent ) {
2359
+ // Store the current set of interactions on the FiberRoot for a few reasons:
2360
+ // We can re-use it in hot functions like renderRoot() without having to
2361
+ // recalculate it. This also provides DevTools with a way to access it when
2362
+ // the onCommitRoot() hook is called.
2363
+ const pendingUpdatersMap = root . pendingUpdatersMap ;
2364
+ pendingUpdatersMap . forEach ( ( updaters , scheduledExpirationTime ) => {
2365
+ if ( scheduledExpirationTime >= expirationTime ) {
2366
+ pendingUpdatersMap . delete ( scheduledExpirationTime ) ;
2367
+ updaters . forEach ( fiber => {
2368
+ root . memoizedUpdaters . add ( fiber ) ;
2369
+ } ) ;
2370
+ }
2371
+ } ) ;
2372
+ }
2340
2373
}
2341
2374
2342
2375
if ( enableSchedulerTracing ) {
0 commit comments