Skip to content

Commit ddac63a

Browse files
committed
Only use the Timeout update queue to store promises, not for state
It already worked this way in practice.
1 parent f48e707 commit ddac63a

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ import {
6464
reconcileChildFibers,
6565
cloneChildFibers,
6666
} from './ReactChildFiber';
67-
import {
68-
createUpdate,
69-
enqueueCapturedUpdate,
70-
processUpdateQueue,
71-
} from './ReactUpdateQueue';
67+
import {processUpdateQueue} from './ReactUpdateQueue';
7268
import {NoWork, Never} from './ReactFiberExpirationTime';
7369
import {AsyncMode, StrictMode} from './ReactTypeOfMode';
7470
import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt';
@@ -734,33 +730,34 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
734730
const nextProps = workInProgress.pendingProps;
735731
const prevProps = workInProgress.memoizedProps;
736732

737-
// Unless we already captured a promise during this render, reset the
738-
// placeholder state back to false. We always attempt to render the real
739-
// children before falling back to the placeholder.
740-
if ((workInProgress.effectTag & DidCapture) === NoEffect) {
741-
const update = createUpdate(renderExpirationTime);
742-
update.process = () => false;
743-
enqueueCapturedUpdate(workInProgress, update, renderExpirationTime);
744-
}
733+
const prevDidTimeout = workInProgress.memoizedState;
745734

746-
const prevState = workInProgress.memoizedState;
735+
// The update queue is only used to store expired promises, and to
736+
// schedule a re-render once an expired promise resolves. It does not
737+
// determine whether we should show the placeholder state, because we
738+
// always attempt to show the placeholder state on every render.
747739
const updateQueue = workInProgress.updateQueue;
748740
if (updateQueue !== null) {
749741
processUpdateQueue(workInProgress, updateQueue, renderExpirationTime);
750742
}
751-
const nextState = workInProgress.memoizedState;
743+
744+
// Check if we already attempted to render the normal state. If we did,
745+
// and we timed out, render the placeholder state.
746+
const alreadyCaptured =
747+
(workInProgress.effectTag & DidCapture) === NoEffect;
748+
const nextDidTimeout = !alreadyCaptured;
752749

753750
if (hasLegacyContextChanged()) {
754751
// Normally we can bail out on props equality but if context has changed
755752
// we don't do the bailout and we have to reuse existing props instead.
756-
} else if (nextProps === prevProps && nextState === prevState) {
753+
} else if (nextProps === prevProps && nextDidTimeout === prevDidTimeout) {
757754
return bailoutOnAlreadyFinishedWork(current, workInProgress);
758755
}
759756

760-
const didTimeout = nextState;
761757
const render = nextProps.children;
762-
const nextChildren = render(didTimeout);
758+
const nextChildren = render(nextDidTimeout);
763759
workInProgress.memoizedProps = nextProps;
760+
workInProgress.memoizedState = nextDidTimeout;
764761
reconcileChildren(current, workInProgress, nextChildren);
765762
return workInProgress.child;
766763
} else {

packages/react-reconciler/src/ReactFiberUnwindWork.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ export default function<C, CX>(
297297
if ((workInProgress.effectTag & DidCapture) === NoEffect) {
298298
workInProgress.effectTag |= ShouldCapture;
299299
const update = createUpdate(renderExpirationTime);
300-
update.process = () => true;
301300
update.commit = finishedWork => {
302301
waitForPromiseAndScheduleRecovery(finishedWork, thenable);
303302
};

0 commit comments

Comments
 (0)