@@ -30,6 +30,7 @@ export type HandleErrorInfo = {
30
30
componentStack : string ,
31
31
} ;
32
32
33
+ var ReactFeatureFlags = require ( 'ReactFeatureFlags' ) ;
33
34
var { popContextProvider} = require ( 'ReactFiberContext' ) ;
34
35
const { reset} = require ( 'ReactFiberStack' ) ;
35
36
var {
@@ -1381,7 +1382,57 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
1381
1382
isReplace : boolean ,
1382
1383
isForced : boolean ,
1383
1384
) {
1384
- const expirationTime = getExpirationTime ( fiber , false ) ;
1385
+ let expirationTime ;
1386
+ if ( expirationContext !== NoWork ) {
1387
+ // An explicit expiration context was set;
1388
+ expirationTime = expirationContext ;
1389
+ } else if ( isPerformingWork ) {
1390
+ if ( isCommitting ) {
1391
+ // Updates that occur during the commit phase should have task priority
1392
+ // by default.
1393
+ expirationTime = Task ;
1394
+ } else {
1395
+ // Updates during the render phase should expire at the same time as
1396
+ // the work that is being rendered.
1397
+ expirationTime = nextRenderExpirationTime ;
1398
+ }
1399
+ } else {
1400
+ // No explicit expiration context was set, and we're not currently
1401
+ // performing work. Calculate a new expiration time.
1402
+
1403
+ let forceAsync = false ;
1404
+ if ( fiber . tag === HostRoot ) {
1405
+ // Check if the top-level element is an async wrapper component. If so,
1406
+ // treat updates to the root as async. This is a bit weird but lets us
1407
+ // avoid a separate `renderAsync` API.
1408
+ const element = ( partialState : any ) . element ;
1409
+ forceAsync =
1410
+ ReactFeatureFlags . enableAsyncSubtreeAPI &&
1411
+ element != null &&
1412
+ element . type != null &&
1413
+ element . type . prototype != null &&
1414
+ ( element . type . prototype : any ) . unstable_isAsyncReactComponent === true ;
1415
+ }
1416
+
1417
+ if (
1418
+ useSyncScheduling &&
1419
+ ! ( fiber . internalContextTag & AsyncUpdates ) &&
1420
+ ! forceAsync
1421
+ ) {
1422
+ // This is a sync update
1423
+ expirationTime = Sync ;
1424
+ } else {
1425
+ // This is an async update
1426
+ const currentTime = recalculateCurrentTime ( ) ;
1427
+ expirationTime = asyncExpirationTime ( currentTime ) ;
1428
+ }
1429
+ }
1430
+
1431
+ if ( expirationTime === Sync && ( isCommitting || isBatchingUpdates ) ) {
1432
+ // If we're in a batch, or in the commit phase, downgrade sync to task
1433
+ expirationTime = Task ;
1434
+ }
1435
+
1385
1436
const update = {
1386
1437
expirationTime,
1387
1438
partialState,
@@ -1506,48 +1557,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
1506
1557
}
1507
1558
}
1508
1559
1509
- function getExpirationTime (
1510
- fiber : Fiber ,
1511
- forceAsync : boolean ,
1512
- ) : ExpirationTime {
1513
- let expirationTime ;
1514
- if ( expirationContext !== NoWork ) {
1515
- // An explicit expiration context was set;
1516
- expirationTime = expirationContext ;
1517
- } else if ( isPerformingWork ) {
1518
- if ( isCommitting ) {
1519
- // Updates that occur during the commit phase should have task priority
1520
- // by default.
1521
- expirationTime = Task ;
1522
- } else {
1523
- // Updates during the render phase should expire at the same time as
1524
- // the work that is being rendered.
1525
- expirationTime = nextRenderExpirationTime ;
1526
- }
1527
- } else {
1528
- // No explicit expiration context was set, and we're not currently
1529
- // performing work. Calculate a new expiration time.
1530
- if (
1531
- useSyncScheduling &&
1532
- ! ( fiber . internalContextTag & AsyncUpdates ) &&
1533
- ! forceAsync
1534
- ) {
1535
- // This is a sync update
1536
- expirationTime = Sync ;
1537
- } else {
1538
- // This is an async update
1539
- const currentTime = recalculateCurrentTime ( ) ;
1540
- expirationTime = asyncExpirationTime ( currentTime ) ;
1541
- }
1542
- }
1543
-
1544
- if ( expirationTime === Sync && ( isCommitting || isBatchingUpdates ) ) {
1545
- // If we're in a batch, or in the commit phase, downgrade sync to task
1546
- return Task ;
1547
- }
1548
- return expirationTime ;
1549
- }
1550
-
1551
1560
function scheduleErrorRecovery ( fiber : Fiber ) {
1552
1561
scheduleWorkImpl ( fiber , Task , true ) ;
1553
1562
}
@@ -1620,8 +1629,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
1620
1629
}
1621
1630
1622
1631
return {
1623
- scheduleWork : scheduleWork ,
1624
- getExpirationTime : getExpirationTime ,
1632
+ scheduleUpdate : scheduleUpdate ,
1625
1633
batchedUpdates : batchedUpdates ,
1626
1634
unbatchedUpdates : unbatchedUpdates ,
1627
1635
flushSync : flushSync ,
0 commit comments