Skip to content

Commit

Permalink
Revert "Revert soft expiration"
Browse files Browse the repository at this point in the history
This reverts commit 6e00daa5077d6ed73312cbb7d12634c1b4acbf89.
  • Loading branch information
acdlite committed Feb 27, 2018
1 parent 7166ce6 commit f215727
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
Mode,
ContextProvider,
ContextConsumer,
LoadingComponent,
TimeoutComponent,
} from 'shared/ReactTypeOfWork';
import getComponentName from 'shared/getComponentName';
Expand All @@ -43,6 +44,7 @@ import {
REACT_PROVIDER_TYPE,
REACT_CONTEXT_TYPE,
REACT_ASYNC_MODE_TYPE,
REACT_LOADING_TYPE,
REACT_TIMEOUT_TYPE,
} from 'shared/ReactSymbols';

Expand Down Expand Up @@ -349,6 +351,9 @@ export function createFiberFromElement(
case REACT_RETURN_TYPE:
fiberTag = ReturnComponent;
break;
case REACT_LOADING_TYPE:
fiberTag = LoadingComponent;
break;
case REACT_TIMEOUT_TYPE:
fiberTag = TimeoutComponent;
break;
Expand Down
48 changes: 48 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
Mode,
ContextProvider,
ContextConsumer,
LoadingComponent,
TimeoutComponent,
} from 'shared/ReactTypeOfWork';
import {
Expand Down Expand Up @@ -728,6 +729,47 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
return workInProgress.stateNode;
}

function updateLoadingComponent(
current,
workInProgress,
renderExpirationTime,
) {
const nextProps = workInProgress.pendingProps;
const prevProps = workInProgress.memoizedProps;

let nextState = workInProgress.memoizedState;
if (nextState === null) {
nextState = workInProgress.memoizedState = false;
}
const prevState = current === null ? nextState : current.memoizedState;

const updateQueue = workInProgress.updateQueue;
if (updateQueue !== null) {
nextState = workInProgress.memoizedState = processUpdateQueue(
current,
workInProgress,
updateQueue,
null,
nextProps,
renderExpirationTime,
);
}

const isLoading = nextState;
if (hasLegacyContextChanged()) {
// Normally we can bail out on props equality but if context has changed
// we don't do the bailout and we have to reuse existing props instead.
} else if (prevProps === nextProps && prevState === nextState) {
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}

const render = nextProps.children;
const nextChildren = render(isLoading);
workInProgress.memoizedProps = nextProps;
reconcileChildren(current, workInProgress, nextChildren);
return workInProgress.child;
}

function updateTimeoutComponent(
current,
workInProgress,
Expand Down Expand Up @@ -1155,6 +1197,12 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
// A return component is just a placeholder, we can just run through the
// next one immediately.
return null;
case LoadingComponent:
return updateLoadingComponent(
current,
workInProgress,
renderExpirationTime,
);
case TimeoutComponent:
return updateTimeoutComponent(
current,
Expand Down
7 changes: 7 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
HostText,
HostPortal,
CallComponent,
LoadingComponent,
TimeoutComponent,
} from 'shared/ReactTypeOfWork';
import ReactErrorUtils from 'shared/ReactErrorUtils';
Expand Down Expand Up @@ -244,6 +245,9 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
// We have no life-cycles associated with portals.
return;
}
case LoadingComponent: {
return;
}
case TimeoutComponent: {
const updateQueue = finishedWork.updateQueue;
if (updateQueue !== null) {
Expand Down Expand Up @@ -814,6 +818,9 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
case HostRoot: {
return;
}
case LoadingComponent: {
return;
}
case TimeoutComponent: {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
ContextConsumer,
Fragment,
Mode,
LoadingComponent,
TimeoutComponent,
} from 'shared/ReactTypeOfWork';
import {
Expand Down Expand Up @@ -606,6 +607,8 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
case ReturnComponent:
// Does nothing.
return null;
case LoadingComponent:
return null;
case TimeoutComponent:
if (workInProgress.effectTag & DidCapture) {
workInProgress.effectTag |= Update;
Expand Down
7 changes: 6 additions & 1 deletion packages/react-reconciler/src/ReactFiberUpdateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
debugRenderPhaseSideEffectsForStrictMode,
} from 'shared/ReactFeatureFlags';
import {Callback as CallbackEffect} from 'shared/ReactTypeOfSideEffect';
import {ClassComponent, HostRoot} from 'shared/ReactTypeOfWork';
import {
ClassComponent,
HostRoot,
LoadingComponent,
} from 'shared/ReactTypeOfWork';
import invariant from 'fbjs/lib/invariant';
import warning from 'fbjs/lib/warning';
import {StrictMode} from './ReactTypeOfMode';
Expand Down Expand Up @@ -194,6 +198,7 @@ export function getUpdateExpirationTime(fiber: Fiber): ExpirationTime {
switch (fiber.tag) {
case HostRoot:
case ClassComponent:
case LoadingComponent:
const updateQueue = fiber.updateQueue;
if (updateQueue === null) {
return NoWork;
Expand Down
Loading

0 comments on commit f215727

Please sign in to comment.