Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bc3e2f9
Basic partial hydration test
sebmarkbage Jan 18, 2019
433e6e5
Render comments around Suspense components
sebmarkbage Jan 19, 2019
2d28a52
Add DehydratedSuspenseComponent type of work
sebmarkbage Jan 24, 2019
f06a540
Add comment node as hydratable instance type as placeholder for suspense
sebmarkbage Jan 24, 2019
97a6664
Skip past nodes within the Suspense boundary
sebmarkbage Jan 28, 2019
1b3e0a2
A dehydrated suspense boundary comment should be considered a sibling
sebmarkbage Jan 28, 2019
6febcae
Retry hydrating at offscreen pri or after ping if suspended
sebmarkbage Jan 28, 2019
7af0b8a
Enter hydration state when retrying dehydrated suspense boundary
sebmarkbage Jan 28, 2019
dac0688
Delete all children within a dehydrated suspense boundary when it's d…
sebmarkbage Jan 28, 2019
92fb62a
Delete server rendered content when props change before hydration com…
sebmarkbage Jan 29, 2019
6ae914c
Make test internal
sebmarkbage Jan 29, 2019
e144a5e
Wrap in act
sebmarkbage Feb 10, 2019
eb3ea2d
Change SSR Fixture to use Partial Hydration
sebmarkbage Feb 9, 2019
97eb545
Changes to any parent Context forces clearing dehydrated content
sebmarkbage Feb 10, 2019
c91092b
Wrap in feature flag
sebmarkbage Feb 11, 2019
2e16dc1
Treat Suspense boundaries without fallbacks as if not-boundaries
sebmarkbage Feb 12, 2019
1db9dd2
Fix clearing of nested suspense boundaries
sebmarkbage Feb 12, 2019
3a89f65
ping -> retry
acdlite Feb 12, 2019
e0e1ded
Typo
acdlite Feb 12, 2019
ca2d628
Use didReceiveUpdate instead of manually comparing props
sebmarkbage Feb 12, 2019
34a132c
Leave comment for why it's ok to ignore the timeout
sebmarkbage Feb 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add DehydratedSuspenseComponent type of work
Will be used for Suspense boundaries that are left with their server
rendered content intact.
  • Loading branch information
sebmarkbage committed Feb 9, 2019
commit 2d28a52f254caa993d51004010698144f53d2de6
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactDebugFiberPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ContextConsumer,
Mode,
SuspenseComponent,
DehydratedSuspenseComponent,
} from 'shared/ReactWorkTags';

type MeasurementPhase =
Expand Down Expand Up @@ -317,7 +318,8 @@ export function stopFailedWorkTimer(fiber: Fiber): void {
}
fiber._debugIsCurrentlyTiming = false;
const warning =
fiber.tag === SuspenseComponent
fiber.tag === SuspenseComponent ||
fiber.tag === DehydratedSuspenseComponent
? 'Rendering was suspended'
: 'An error was thrown inside this error boundary';
endFiberMark(fiber, null, warning);
Expand Down
18 changes: 18 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 {
ContextConsumer,
Profiler,
SuspenseComponent,
DehydratedSuspenseComponent,
MemoComponent,
SimpleMemoComponent,
LazyComponent,
Expand Down Expand Up @@ -1392,6 +1393,13 @@ function updateSuspenseComponent(
// children -- we skip over the primary children entirely.
let next;
if (current === null) {
// If we're currently hydrating, try to hydrate this boundary.
tryToClaimNextHydratableInstance(workInProgress);
// This could've changed the tag if this was a dehydrated suspense component.
if (workInProgress.tag === DehydratedSuspenseComponent) {
return updateDehydratedSuspenseComponent(null, workInProgress);
}

// This is the initial mount. This branch is pretty simple because there's
// no previous state that needs to be preserved.
if (nextDidTimeout) {
Expand Down Expand Up @@ -1598,6 +1606,13 @@ function updateSuspenseComponent(
return next;
}

function updateDehydratedSuspenseComponent(
current: Fiber | null,
workInProgress: Fiber,
) {
return null;
}

function updatePortalComponent(
current: Fiber | null,
workInProgress: Fiber,
Expand Down Expand Up @@ -2051,6 +2066,9 @@ function beginWork(
renderExpirationTime,
);
}
case DehydratedSuspenseComponent: {
return updateDehydratedSuspenseComponent(current, workInProgress);
}
default:
invariant(
false,
Expand Down
12 changes: 12 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 {
Mode,
Profiler,
SuspenseComponent,
DehydratedSuspenseComponent,
MemoComponent,
SimpleMemoComponent,
LazyComponent,
Expand Down Expand Up @@ -762,6 +763,17 @@ function completeWork(
}
break;
}
case DehydratedSuspenseComponent: {
if (current === null) {
let wasHydrated = popHydrationState(workInProgress);
invariant(
wasHydrated,
'A dehydrated suspense component was completed without a hydrated node. ' +
'This is probably a bug in React.',
);
}
break;
}
default:
invariant(
false,
Expand Down
10 changes: 10 additions & 0 deletions packages/react-reconciler/src/ReactFiberSuspenseComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ export function shouldCaptureSuspense(workInProgress: Fiber): boolean {
const nextState: SuspenseState | null = workInProgress.memoizedState;
return nextState === null;
}

export function shouldCaptureDehydratedSuspense(
workInProgress: Fiber,
): boolean {
// In order to capture, the Suspense component must have a fallback prop.
if (workInProgress.memoizedProps.fallback === undefined) {
return false;
}
return true;
}
20 changes: 19 additions & 1 deletion packages/react-reconciler/src/ReactFiberUnwindWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
HostPortal,
ContextProvider,
SuspenseComponent,
DehydratedSuspenseComponent,
IncompleteClassComponent,
} from 'shared/ReactWorkTags';
import {
Expand All @@ -36,7 +37,10 @@ import {
} from 'shared/ReactSideEffectTags';
import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
import {ConcurrentMode} from './ReactTypeOfMode';
import {shouldCaptureSuspense} from './ReactFiberSuspenseComponent';
import {
shouldCaptureSuspense,
shouldCaptureDehydratedSuspense,
} from './ReactFiberSuspenseComponent';

import {createCapturedValue} from './ReactCapturedValue';
import {
Expand Down Expand Up @@ -197,6 +201,8 @@ function throwException(
earliestTimeoutMs = timeoutPropMs;
}
}
} else if (workInProgress.tag === DehydratedSuspenseComponent) {
// TODO
}
workInProgress = workInProgress.return;
} while (workInProgress !== null);
Expand Down Expand Up @@ -334,6 +340,12 @@ function throwException(
workInProgress.effectTag |= ShouldCapture;
workInProgress.expirationTime = renderExpirationTime;
return;
} else if (
workInProgress.tag === DehydratedSuspenseComponent &&
shouldCaptureDehydratedSuspense(workInProgress)
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this branch doesn't suspend (it doesn't call renderDidSuspend) I would expect React to keep rendering the same level over and over until the promise resolves. Is that what's happening?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. What happens is that only the first path schedules remaining work at "Never" expiration time. Then if it throws, it doesn't suspend but it also doesn't leave any work on it. Instead it commits. Then it waits for the retry. The retry gets scheduled at normal priority. If that update also throws a promise, then it commits in the dehydrated state again and waits for the retry.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see so when something suspends inside a dehydrated Suspense boundary it always bails out and clears the expiration time. The ping/retry adds the expiration time back. There’s no need to suspend the commit because it’s not blocking anything.

// TODO
return;
}
// This boundary already captured during this render. Continue to the next
// boundary.
Expand Down Expand Up @@ -432,6 +444,7 @@ function unwindWork(
return workInProgress;
}
case HostComponent: {
// TODO: popHydrationState
popHostContext(workInProgress);
return null;
}
Expand All @@ -444,6 +457,11 @@ function unwindWork(
}
return null;
}
case DehydratedSuspenseComponent: {
// TODO: popHydrationState
// TODO: Maybe re-render if it captured?
return null;
}
case HostPortal:
popHostContainer(workInProgress);
return null;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/ReactWorkTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ export const MemoComponent = 14;
export const SimpleMemoComponent = 15;
export const LazyComponent = 16;
export const IncompleteClassComponent = 17;
export const DehydratedSuspenseComponent = 18;