Skip to content

Commit

Permalink
Use the new approach of leaving work at normal pri to replace fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Mar 9, 2019
1 parent 0aed005 commit 5dde36e
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import {
cloneChildFibers,
} from './ReactChildFiber';
import {processUpdateQueue} from './ReactUpdateQueue';
import {NoWork, Never} from './ReactFiberExpirationTime';
import {NoWork, Never, computeAsyncExpiration} from './ReactFiberExpirationTime';
import {
ConcurrentMode,
NoContext,
Expand Down Expand Up @@ -133,7 +133,7 @@ import {
createWorkInProgress,
isSimpleFunctionComponent,
} from './ReactFiber';
import {retryTimedOutBoundary} from './ReactFiberScheduler';
import {requestCurrentTime, retryTimedOutBoundary} from './ReactFiberScheduler';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

Expand Down Expand Up @@ -1672,10 +1672,30 @@ function updateDehydratedSuspenseComponent(
workInProgress: Fiber,
renderExpirationTime: ExpirationTime,
) {
const suspenseInstance = (workInProgress.stateNode: SuspenseInstance);
if (current === null) {
// During the first pass, we'll bail out and not drill into the children.
// Instead, we'll leave the content in place and try to hydrate it later.
workInProgress.expirationTime = Never;
if (isSuspenseInstanceFallback(suspenseInstance)) {
// This is a client-only boundary. Since we won't get any content from the server
// for this, we need to schedule that at a higher priority based on when it would
// have timed out. In theory we could render it in this pass but it would have the
// wrong priority associated with it and will prevent hydration of parent path.
// Instead, we'll leave work left on it to render it in a separate commit.

// TODO This time should be the time at which the server rendered response that is
// a parent to this boundary was displayed. However, since we currently don't have
// a protocol to transfer that time, we'll just estimate it by using the current
// time. This will mean that Suspense timeouts are slightly shifted to later than
// they should be.
let serverDisplayTime = requestCurrentTime();
// Schedule a normal pri update to render this content.
workInProgress.expirationTime = computeAsyncExpiration(serverDisplayTime);
} else {
// We'll continue hydrating the rest at offscreen priority since we'll already
// be showing the right content coming from the server, it is no rush.
workInProgress.expirationTime = Never;
}
return null;
}
if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
Expand All @@ -1684,7 +1704,6 @@ function updateDehydratedSuspenseComponent(
workInProgress.child = null;
return null;
}
const suspenseInstance = (current.stateNode: SuspenseInstance);
if (isSuspenseInstanceFallback(suspenseInstance)) {
// This boundary is in a permanent fallback state. In this case, we'll never
// get an update and we'll never be able to hydrate the final content. Let's just try the
Expand Down

0 comments on commit 5dde36e

Please sign in to comment.