Skip to content

Commit 1990983

Browse files
committed
Remove getExpirationTime
The last remaining use for getExpirationTime was for top-level async updates. I moved that check to scheduleUpdate instead.
1 parent d99be5c commit 1990983

File tree

2 files changed

+56
-73
lines changed

2 files changed

+56
-73
lines changed

src/renderers/shared/fiber/ReactFiberReconciler.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import type {Fiber} from 'ReactFiber';
1414
import type {FiberRoot} from 'ReactFiberRoot';
1515
import type {ReactNodeList} from 'ReactTypes';
1616

17-
var ReactFeatureFlags = require('ReactFeatureFlags');
18-
19-
var {insertUpdateIntoFiber} = require('ReactFiberUpdateQueue');
20-
2117
var {
2218
findCurrentUnmaskedContext,
2319
isContextProvider,
@@ -235,8 +231,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
235231
var {getPublicInstance} = config;
236232

237233
var {
238-
scheduleWork,
239-
getExpirationTime,
234+
scheduleUpdate,
240235
batchedUpdates,
241236
unbatchedUpdates,
242237
flushSync,
@@ -266,17 +261,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
266261
}
267262
}
268263

269-
// Check if the top-level element is an async wrapper component. If so, treat
270-
// updates to the root as async. This is a bit weird but lets us avoid a separate
271-
// `renderAsync` API.
272-
const forceAsync =
273-
ReactFeatureFlags.enableAsyncSubtreeAPI &&
274-
element != null &&
275-
element.type != null &&
276-
element.type.prototype != null &&
277-
(element.type.prototype: any).unstable_isAsyncReactComponent === true;
278-
const expirationTime = getExpirationTime(current, forceAsync);
279-
const nextState = {element};
280264
callback = callback === undefined ? null : callback;
281265
if (__DEV__) {
282266
warning(
@@ -286,17 +270,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
286270
callback,
287271
);
288272
}
289-
const update = {
290-
expirationTime,
291-
partialState: nextState,
292-
callback,
293-
isReplace: false,
294-
isForced: false,
295-
nextCallback: null,
296-
next: null,
297-
};
298-
insertUpdateIntoFiber(current, update);
299-
scheduleWork(current, expirationTime);
273+
const state = {element};
274+
scheduleUpdate(current, state, callback, false, false);
300275
}
301276

302277
return {

src/renderers/shared/fiber/ReactFiberScheduler.js

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type HandleErrorInfo = {
3030
componentStack: string,
3131
};
3232

33+
var ReactFeatureFlags = require('ReactFeatureFlags');
3334
var {popContextProvider} = require('ReactFiberContext');
3435
const {reset} = require('ReactFiberStack');
3536
var {
@@ -1381,7 +1382,57 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
13811382
isReplace: boolean,
13821383
isForced: boolean,
13831384
) {
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+
13851436
const update = {
13861437
expirationTime,
13871438
partialState,
@@ -1506,48 +1557,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
15061557
}
15071558
}
15081559

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-
15511560
function scheduleErrorRecovery(fiber: Fiber) {
15521561
scheduleWorkImpl(fiber, Task, true);
15531562
}
@@ -1620,8 +1629,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
16201629
}
16211630

16221631
return {
1623-
scheduleWork: scheduleWork,
1624-
getExpirationTime: getExpirationTime,
1632+
scheduleUpdate: scheduleUpdate,
16251633
batchedUpdates: batchedUpdates,
16261634
unbatchedUpdates: unbatchedUpdates,
16271635
flushSync: flushSync,

0 commit comments

Comments
 (0)