@@ -22,7 +22,6 @@ import type {
22
22
TransitionAbort ,
23
23
} from './ReactFiberTracingMarkerComponent' ;
24
24
import type { OffscreenInstance } from './ReactFiberActivityComponent' ;
25
- import type { RenderTaskFn } from './ReactFiberRootScheduler' ;
26
25
import type { Resource } from './ReactFiberConfig' ;
27
26
28
27
import {
@@ -32,7 +31,6 @@ import {
32
31
enableProfilerNestedUpdatePhase ,
33
32
enableDebugTracing ,
34
33
enableSchedulingProfiler ,
35
- disableSchedulerTimeoutInWorkLoop ,
36
34
enableUpdaterTracking ,
37
35
enableCache ,
38
36
enableTransitionTracing ,
@@ -250,11 +248,9 @@ import {
250
248
recordRenderTime ,
251
249
recordCommitTime ,
252
250
recordCommitEndTime ,
253
- resetNestedUpdateFlag ,
254
251
startProfilerTimer ,
255
252
stopProfilerTimerIfRunningAndRecordDuration ,
256
253
stopProfilerTimerIfRunningAndRecordIncompleteDuration ,
257
- syncNestedUpdateFlag ,
258
254
} from './ReactProfilerTimer' ;
259
255
import { setCurrentTrackFromLanes } from './ReactFiberPerformanceTrack' ;
260
256
@@ -308,7 +304,6 @@ import {
308
304
ensureRootIsScheduled ,
309
305
flushSyncWorkOnAllRoots ,
310
306
flushSyncWorkOnLegacyRootsOnly ,
311
- getContinuationForRoot ,
312
307
requestTransitionLane ,
313
308
} from './ReactFiberRootScheduler' ;
314
309
import { getMaskedContext , getUnmaskedContext } from './ReactFiberContext' ;
@@ -890,59 +885,22 @@ export function isUnsafeClassRenderPhaseUpdate(fiber: Fiber): boolean {
890
885
return ( executionContext & RenderContext ) !== NoContext ;
891
886
}
892
887
893
- // This is the entry point for every concurrent task, i.e. anything that
894
- // goes through Scheduler.
895
- export function performConcurrentWorkOnRoot (
888
+ export function performWorkOnRoot (
896
889
root : FiberRoot ,
897
- didTimeout : boolean ,
898
- ) : RenderTaskFn | null {
899
- if ( enableProfilerTimer && enableProfilerNestedUpdatePhase ) {
900
- resetNestedUpdateFlag ( ) ;
901
- }
902
-
890
+ lanes : Lanes ,
891
+ forceSync : boolean ,
892
+ ) : void {
903
893
if ( ( executionContext & ( RenderContext | CommitContext ) ) !== NoContext ) {
904
894
throw new Error ( 'Should not already be working.' ) ;
905
895
}
906
896
907
- // Flush any pending passive effects before deciding which lanes to work on,
908
- // in case they schedule additional work.
909
- const originalCallbackNode = root . callbackNode ;
910
- const didFlushPassiveEffects = flushPassiveEffects ( ) ;
911
- if ( didFlushPassiveEffects ) {
912
- // Something in the passive effect phase may have canceled the current task.
913
- // Check if the task node for this root was changed.
914
- if ( root . callbackNode !== originalCallbackNode ) {
915
- // The current task was canceled. Exit. We don't need to call
916
- // `ensureRootIsScheduled` because the check above implies either that
917
- // there's a new task, or that there's no remaining work on this root.
918
- return null ;
919
- } else {
920
- // Current task was not canceled. Continue.
921
- }
922
- }
923
-
924
- // Determine the next lanes to work on, using the fields stored
925
- // on the root.
926
- // TODO: This was already computed in the caller. Pass it as an argument.
927
- let lanes = getNextLanes (
928
- root ,
929
- root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes ,
930
- ) ;
931
- if ( lanes === NoLanes ) {
932
- // Defensive coding. This is never expected to happen.
933
- return null ;
934
- }
935
-
936
897
// We disable time-slicing in some cases: if the work has been CPU-bound
937
898
// for too long ("expired" work, to prevent starvation), or we're in
938
899
// sync-updates-by-default mode.
939
- // TODO: We only check `didTimeout` defensively, to account for a Scheduler
940
- // bug we're still investigating. Once the bug in Scheduler is fixed,
941
- // we can remove this, since we track expiration ourselves.
942
900
const shouldTimeSlice =
901
+ ! forceSync &&
943
902
! includesBlockingLane ( lanes ) &&
944
- ! includesExpiredLane ( root , lanes ) &&
945
- ( disableSchedulerTimeoutInWorkLoop || ! didTimeout ) ;
903
+ ! includesExpiredLane ( root , lanes ) ;
946
904
let exitStatus = shouldTimeSlice
947
905
? renderRootConcurrent ( root , lanes )
948
906
: renderRootSync ( root , lanes ) ;
@@ -984,7 +942,10 @@ export function performConcurrentWorkOnRoot(
984
942
}
985
943
986
944
// Check if something threw
987
- if ( exitStatus === RootErrored ) {
945
+ if (
946
+ ( disableLegacyMode || root . tag !== LegacyRoot ) &&
947
+ exitStatus === RootErrored
948
+ ) {
988
949
const lanesThatJustErrored = lanes ;
989
950
const errorRetryLanes = getLanesToRetrySynchronouslyOnError (
990
951
root ,
@@ -1033,7 +994,6 @@ export function performConcurrentWorkOnRoot(
1033
994
}
1034
995
1035
996
ensureRootIsScheduled ( root ) ;
1036
- return getContinuationForRoot ( root , originalCallbackNode ) ;
1037
997
}
1038
998
1039
999
function recoverFromConcurrentError (
@@ -1464,104 +1424,6 @@ function markRootSuspended(
1464
1424
) ;
1465
1425
}
1466
1426
1467
- // This is the entry point for synchronous tasks that don't go
1468
- // through Scheduler
1469
- export function performSyncWorkOnRoot ( root : FiberRoot , lanes : Lanes ) : null {
1470
- if ( ( executionContext & ( RenderContext | CommitContext ) ) !== NoContext ) {
1471
- throw new Error ( 'Should not already be working.' ) ;
1472
- }
1473
-
1474
- const didFlushPassiveEffects = flushPassiveEffects ( ) ;
1475
- if ( didFlushPassiveEffects ) {
1476
- // If passive effects were flushed, exit to the outer work loop in the root
1477
- // scheduler, so we can recompute the priority.
1478
- // TODO: We don't actually need this `ensureRootIsScheduled` call because
1479
- // this path is only reachable if the root is already part of the schedule.
1480
- // I'm including it only for consistency with the other exit points from
1481
- // this function. Can address in a subsequent refactor.
1482
- ensureRootIsScheduled ( root ) ;
1483
- return null ;
1484
- }
1485
-
1486
- if ( enableProfilerTimer && enableProfilerNestedUpdatePhase ) {
1487
- syncNestedUpdateFlag ( ) ;
1488
- }
1489
-
1490
- let exitStatus = renderRootSync ( root , lanes ) ;
1491
- if (
1492
- ( disableLegacyMode || root . tag !== LegacyRoot ) &&
1493
- exitStatus === RootErrored
1494
- ) {
1495
- // If something threw an error, try rendering one more time. We'll render
1496
- // synchronously to block concurrent data mutations, and we'll includes
1497
- // all pending updates are included. If it still fails after the second
1498
- // attempt, we'll give up and commit the resulting tree.
1499
- const originallyAttemptedLanes = lanes ;
1500
- const errorRetryLanes = getLanesToRetrySynchronouslyOnError (
1501
- root ,
1502
- originallyAttemptedLanes ,
1503
- ) ;
1504
- if ( errorRetryLanes !== NoLanes ) {
1505
- lanes = errorRetryLanes ;
1506
- exitStatus = recoverFromConcurrentError (
1507
- root ,
1508
- originallyAttemptedLanes ,
1509
- errorRetryLanes ,
1510
- ) ;
1511
- }
1512
- }
1513
-
1514
- if ( exitStatus === RootFatalErrored ) {
1515
- prepareFreshStack ( root , NoLanes ) ;
1516
- markRootSuspended ( root , lanes , NoLane , false ) ;
1517
- ensureRootIsScheduled ( root ) ;
1518
- return null ;
1519
- }
1520
-
1521
- if ( exitStatus === RootDidNotComplete ) {
1522
- // The render unwound without completing the tree. This happens in special
1523
- // cases where need to exit the current render without producing a
1524
- // consistent tree or committing.
1525
- markRootSuspended (
1526
- root ,
1527
- lanes ,
1528
- workInProgressDeferredLane ,
1529
- workInProgressRootDidSkipSuspendedSiblings ,
1530
- ) ;
1531
- ensureRootIsScheduled ( root ) ;
1532
- return null ;
1533
- }
1534
-
1535
- let renderEndTime = 0 ;
1536
- if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
1537
- renderEndTime = now ( ) ;
1538
- }
1539
-
1540
- // We now have a consistent tree. Because this is a sync render, we
1541
- // will commit it even if something suspended.
1542
- const finishedWork : Fiber = ( root . current . alternate : any ) ;
1543
- root . finishedWork = finishedWork ;
1544
- root . finishedLanes = lanes ;
1545
- commitRoot (
1546
- root ,
1547
- workInProgressRootRecoverableErrors ,
1548
- workInProgressTransitions ,
1549
- workInProgressRootDidIncludeRecursiveRenderUpdate ,
1550
- workInProgressDeferredLane ,
1551
- workInProgressRootInterleavedUpdatedLanes ,
1552
- workInProgressSuspendedRetryLanes ,
1553
- IMMEDIATE_COMMIT ,
1554
- renderStartTime ,
1555
- renderEndTime ,
1556
- ) ;
1557
-
1558
- // Before exiting, make sure there's a callback scheduled for the next
1559
- // pending level.
1560
- ensureRootIsScheduled ( root ) ;
1561
-
1562
- return null ;
1563
- }
1564
-
1565
1427
export function flushRoot ( root : FiberRoot , lanes : Lanes ) {
1566
1428
if ( lanes !== NoLanes ) {
1567
1429
upgradePendingLanesToSync ( root , lanes ) ;
0 commit comments