Skip to content

Commit

Permalink
Remove getExpirationTime
Browse files Browse the repository at this point in the history
The last remaining use for getExpirationTime was for top-level async
updates. I moved that check to scheduleUpdate instead.
  • Loading branch information
acdlite committed Oct 12, 2017
1 parent d99be5c commit 1990983
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 73 deletions.
31 changes: 3 additions & 28 deletions src/renderers/shared/fiber/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import type {Fiber} from 'ReactFiber';
import type {FiberRoot} from 'ReactFiberRoot';
import type {ReactNodeList} from 'ReactTypes';

var ReactFeatureFlags = require('ReactFeatureFlags');

var {insertUpdateIntoFiber} = require('ReactFiberUpdateQueue');

var {
findCurrentUnmaskedContext,
isContextProvider,
Expand Down Expand Up @@ -235,8 +231,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
var {getPublicInstance} = config;

var {
scheduleWork,
getExpirationTime,
scheduleUpdate,
batchedUpdates,
unbatchedUpdates,
flushSync,
Expand Down Expand Up @@ -266,17 +261,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
}

// Check if the top-level element is an async wrapper component. If so, treat
// updates to the root as async. This is a bit weird but lets us avoid a separate
// `renderAsync` API.
const forceAsync =
ReactFeatureFlags.enableAsyncSubtreeAPI &&
element != null &&
element.type != null &&
element.type.prototype != null &&
(element.type.prototype: any).unstable_isAsyncReactComponent === true;
const expirationTime = getExpirationTime(current, forceAsync);
const nextState = {element};
callback = callback === undefined ? null : callback;
if (__DEV__) {
warning(
Expand All @@ -286,17 +270,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
callback,
);
}
const update = {
expirationTime,
partialState: nextState,
callback,
isReplace: false,
isForced: false,
nextCallback: null,
next: null,
};
insertUpdateIntoFiber(current, update);
scheduleWork(current, expirationTime);
const state = {element};
scheduleUpdate(current, state, callback, false, false);
}

return {
Expand Down
98 changes: 53 additions & 45 deletions src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type HandleErrorInfo = {
componentStack: string,
};

var ReactFeatureFlags = require('ReactFeatureFlags');
var {popContextProvider} = require('ReactFiberContext');
const {reset} = require('ReactFiberStack');
var {
Expand Down Expand Up @@ -1381,7 +1382,57 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
isReplace: boolean,
isForced: boolean,
) {
const expirationTime = getExpirationTime(fiber, false);
let expirationTime;
if (expirationContext !== NoWork) {
// An explicit expiration context was set;
expirationTime = expirationContext;
} else if (isPerformingWork) {
if (isCommitting) {
// Updates that occur during the commit phase should have task priority
// by default.
expirationTime = Task;
} else {
// Updates during the render phase should expire at the same time as
// the work that is being rendered.
expirationTime = nextRenderExpirationTime;
}
} else {
// No explicit expiration context was set, and we're not currently
// performing work. Calculate a new expiration time.

let forceAsync = false;
if (fiber.tag === HostRoot) {
// Check if the top-level element is an async wrapper component. If so,
// treat updates to the root as async. This is a bit weird but lets us
// avoid a separate `renderAsync` API.
const element = (partialState: any).element;
forceAsync =
ReactFeatureFlags.enableAsyncSubtreeAPI &&
element != null &&
element.type != null &&
element.type.prototype != null &&
(element.type.prototype: any).unstable_isAsyncReactComponent === true;
}

if (
useSyncScheduling &&
!(fiber.internalContextTag & AsyncUpdates) &&
!forceAsync
) {
// This is a sync update
expirationTime = Sync;
} else {
// This is an async update
const currentTime = recalculateCurrentTime();
expirationTime = asyncExpirationTime(currentTime);
}
}

if (expirationTime === Sync && (isCommitting || isBatchingUpdates)) {
// If we're in a batch, or in the commit phase, downgrade sync to task
expirationTime = Task;
}

const update = {
expirationTime,
partialState,
Expand Down Expand Up @@ -1506,48 +1557,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
}

function getExpirationTime(
fiber: Fiber,
forceAsync: boolean,
): ExpirationTime {
let expirationTime;
if (expirationContext !== NoWork) {
// An explicit expiration context was set;
expirationTime = expirationContext;
} else if (isPerformingWork) {
if (isCommitting) {
// Updates that occur during the commit phase should have task priority
// by default.
expirationTime = Task;
} else {
// Updates during the render phase should expire at the same time as
// the work that is being rendered.
expirationTime = nextRenderExpirationTime;
}
} else {
// No explicit expiration context was set, and we're not currently
// performing work. Calculate a new expiration time.
if (
useSyncScheduling &&
!(fiber.internalContextTag & AsyncUpdates) &&
!forceAsync
) {
// This is a sync update
expirationTime = Sync;
} else {
// This is an async update
const currentTime = recalculateCurrentTime();
expirationTime = asyncExpirationTime(currentTime);
}
}

if (expirationTime === Sync && (isCommitting || isBatchingUpdates)) {
// If we're in a batch, or in the commit phase, downgrade sync to task
return Task;
}
return expirationTime;
}

function scheduleErrorRecovery(fiber: Fiber) {
scheduleWorkImpl(fiber, Task, true);
}
Expand Down Expand Up @@ -1620,8 +1629,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}

return {
scheduleWork: scheduleWork,
getExpirationTime: getExpirationTime,
scheduleUpdate: scheduleUpdate,
batchedUpdates: batchedUpdates,
unbatchedUpdates: unbatchedUpdates,
flushSync: flushSync,
Expand Down

0 comments on commit 1990983

Please sign in to comment.