Skip to content

Commit 83b941a

Browse files
committed
Add isRootDehydrated function
Currently this does nothing except read a boolean field, but I'm about to change this logic. Since this is accessed by React DOM, too, I put the function in a separate module that can be deep imported. Previously, it was accessing the FiberRoot directly. The reason it's a separate module is to break a circular dependency between React DOM and the reconciler.
1 parent c8e4789 commit 83b941a

13 files changed

+45
-16
lines changed

packages/react-dom/src/events/ReactDOMEventListener.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
setCurrentUpdatePriority,
5454
} from 'react-reconciler/src/ReactEventPriorities';
5555
import ReactSharedInternals from 'shared/ReactSharedInternals';
56+
import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration';
5657

5758
const {ReactCurrentBatchConfig} = ReactSharedInternals;
5859

@@ -386,7 +387,7 @@ export function findInstanceBlockingEvent(
386387
targetInst = null;
387388
} else if (tag === HostRoot) {
388389
const root: FiberRoot = nearestMounted.stateNode;
389-
if (root.isDehydrated) {
390+
if (isRootDehydrated(root)) {
390391
// If this happens during a replay something went wrong and it might block
391392
// the whole system.
392393
return getContainerFromFiber(nearestMounted);

packages/react-dom/src/events/ReactDOMEventReplaying.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
} from '../client/ReactDOMComponentTree';
4040
import {HostRoot, SuspenseComponent} from 'react-reconciler/src/ReactWorkTags';
4141
import {isHigherEventPriority} from 'react-reconciler/src/ReactEventPriorities';
42+
import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration';
4243

4344
let _attemptSynchronousHydration: (fiber: Object) => void;
4445

@@ -414,7 +415,7 @@ function attemptExplicitHydrationTarget(
414415
}
415416
} else if (tag === HostRoot) {
416417
const root: FiberRoot = nearestMounted.stateNode;
417-
if (root.isDehydrated) {
418+
if (isRootDehydrated(root)) {
418419
queuedTarget.blockedOn = getContainerFromFiber(nearestMounted);
419420
// We don't currently have a way to increase the priority of
420421
// a root other than sync.

packages/react-reconciler/src/ReactFiberBeginWork.new.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ import {
223223
createOffscreenHostContainerFiber,
224224
isSimpleFunctionComponent,
225225
} from './ReactFiber.new';
226+
import {isRootDehydrated} from './ReactFiberShellHydration';
226227
import {
227228
retryDehydratedSuspenseBoundary,
228229
scheduleUpdateOnFiber,
@@ -1351,7 +1352,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13511352
resetHydrationState();
13521353
return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
13531354
}
1354-
if (root.isDehydrated && enterHydrationState(workInProgress)) {
1355+
if (isRootDehydrated(root) && enterHydrationState(workInProgress)) {
13551356
// If we don't have any current children this might be the first pass.
13561357
// We always try to hydrate. If this isn't a hydration pass there won't
13571358
// be any children to hydrate which is effectively the same thing as

packages/react-reconciler/src/ReactFiberBeginWork.old.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ import {
223223
createOffscreenHostContainerFiber,
224224
isSimpleFunctionComponent,
225225
} from './ReactFiber.old';
226+
import {isRootDehydrated} from './ReactFiberShellHydration';
226227
import {
227228
retryDehydratedSuspenseBoundary,
228229
scheduleUpdateOnFiber,
@@ -1351,7 +1352,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13511352
resetHydrationState();
13521353
return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
13531354
}
1354-
if (root.isDehydrated && enterHydrationState(workInProgress)) {
1355+
if (isRootDehydrated(root) && enterHydrationState(workInProgress)) {
13551356
// If we don't have any current children this might be the first pass.
13561357
// We always try to hydrate. If this isn't a hydration pass there won't
13571358
// be any children to hydrate which is effectively the same thing as

packages/react-reconciler/src/ReactFiberCommitWork.new.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
Visibility,
8383
} from './ReactFiberFlags';
8484
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
85+
import {isRootDehydrated} from './ReactFiberShellHydration';
8586
import {
8687
resetCurrentFiber as resetCurrentDebugFiberInDEV,
8788
setCurrentFiber as setCurrentDebugFiberInDEV,
@@ -1878,7 +1879,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
18781879
case HostRoot: {
18791880
if (supportsHydration) {
18801881
const root: FiberRoot = finishedWork.stateNode;
1881-
if (root.isDehydrated) {
1882+
if (isRootDehydrated(root)) {
18821883
// We've just hydrated. No need to hydrate again.
18831884
root.isDehydrated = false;
18841885
commitHydratedContainer(root.containerInfo);
@@ -1986,7 +1987,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
19861987
case HostRoot: {
19871988
if (supportsHydration) {
19881989
const root: FiberRoot = finishedWork.stateNode;
1989-
if (root.isDehydrated) {
1990+
if (isRootDehydrated(root)) {
19901991
// We've just hydrated. No need to hydrate again.
19911992
root.isDehydrated = false;
19921993
commitHydratedContainer(root.containerInfo);

packages/react-reconciler/src/ReactFiberCommitWork.old.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
Visibility,
8383
} from './ReactFiberFlags';
8484
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
85+
import {isRootDehydrated} from './ReactFiberShellHydration';
8586
import {
8687
resetCurrentFiber as resetCurrentDebugFiberInDEV,
8788
setCurrentFiber as setCurrentDebugFiberInDEV,
@@ -1878,7 +1879,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
18781879
case HostRoot: {
18791880
if (supportsHydration) {
18801881
const root: FiberRoot = finishedWork.stateNode;
1881-
if (root.isDehydrated) {
1882+
if (isRootDehydrated(root)) {
18821883
// We've just hydrated. No need to hydrate again.
18831884
root.isDehydrated = false;
18841885
commitHydratedContainer(root.containerInfo);
@@ -1986,7 +1987,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
19861987
case HostRoot: {
19871988
if (supportsHydration) {
19881989
const root: FiberRoot = finishedWork.stateNode;
1989-
if (root.isDehydrated) {
1990+
if (isRootDehydrated(root)) {
19901991
// We've just hydrated. No need to hydrate again.
19911992
root.isDehydrated = false;
19921993
commitHydratedContainer(root.containerInfo);

packages/react-reconciler/src/ReactFiberCompleteWork.new.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ import {
160160
includesSomeLane,
161161
mergeLanes,
162162
} from './ReactFiberLane.new';
163+
import {isRootDehydrated} from './ReactFiberShellHydration';
163164
import {resetChildFibers} from './ReactChildFiber.new';
164165
import {createScopeInstance} from './ReactFiberScope.new';
165166
import {transferActualDuration} from './ReactProfilerTimer.new';
@@ -890,7 +891,7 @@ function completeWork(
890891
// If we hydrated, then we'll need to schedule an update for
891892
// the commit side-effects on the root.
892893
markUpdate(workInProgress);
893-
} else if (!fiberRoot.isDehydrated) {
894+
} else if (!isRootDehydrated(fiberRoot)) {
894895
// Schedule an effect to clear this container at the start of the next commit.
895896
// This handles the case of React rendering into a container with previous children.
896897
// It's also safe to do for updates too, because current.child would only be null

packages/react-reconciler/src/ReactFiberCompleteWork.old.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ import {
160160
includesSomeLane,
161161
mergeLanes,
162162
} from './ReactFiberLane.old';
163+
import {isRootDehydrated} from './ReactFiberShellHydration';
163164
import {resetChildFibers} from './ReactChildFiber.old';
164165
import {createScopeInstance} from './ReactFiberScope.old';
165166
import {transferActualDuration} from './ReactProfilerTimer.old';
@@ -890,7 +891,7 @@ function completeWork(
890891
// If we hydrated, then we'll need to schedule an update for
891892
// the commit side-effects on the root.
892893
markUpdate(workInProgress);
893-
} else if (!fiberRoot.isDehydrated) {
894+
} else if (!isRootDehydrated(fiberRoot)) {
894895
// Schedule an effect to clear this container at the start of the next commit.
895896
// This handles the case of React rendering into a container with previous children.
896897
// It's also safe to do for updates too, because current.child would only be null

packages/react-reconciler/src/ReactFiberReconciler.new.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
isContextProvider as isLegacyContextProvider,
4949
} from './ReactFiberContext.new';
5050
import {createFiberRoot} from './ReactFiberRoot.new';
51+
import {isRootDehydrated} from './ReactFiberShellHydration';
5152
import {
5253
injectInternals,
5354
markRenderScheduled,
@@ -411,7 +412,7 @@ export function attemptSynchronousHydration(fiber: Fiber): void {
411412
switch (fiber.tag) {
412413
case HostRoot:
413414
const root: FiberRoot = fiber.stateNode;
414-
if (root.isDehydrated) {
415+
if (isRootDehydrated(root)) {
415416
// Flush the first scheduled "update".
416417
const lanes = getHighestPriorityPendingLanes(root);
417418
flushRoot(root, lanes);

packages/react-reconciler/src/ReactFiberReconciler.old.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
isContextProvider as isLegacyContextProvider,
4949
} from './ReactFiberContext.old';
5050
import {createFiberRoot} from './ReactFiberRoot.old';
51+
import {isRootDehydrated} from './ReactFiberShellHydration';
5152
import {
5253
injectInternals,
5354
markRenderScheduled,
@@ -411,7 +412,7 @@ export function attemptSynchronousHydration(fiber: Fiber): void {
411412
switch (fiber.tag) {
412413
case HostRoot:
413414
const root: FiberRoot = fiber.stateNode;
414-
if (root.isDehydrated) {
415+
if (isRootDehydrated(root)) {
415416
// Flush the first scheduled "update".
416417
const lanes = getHighestPriorityPendingLanes(root);
417418
flushRoot(root, lanes);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import type {FiberRoot} from './ReactInternalTypes';
11+
12+
// This is imported by the event replaying implementation in React DOM. It's
13+
// in a separate file to break a circular dependency between the renderer and
14+
// the reconciler.
15+
export function isRootDehydrated(root: FiberRoot) {
16+
return root.isDehydrated;
17+
}

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import {
8888
createWorkInProgress,
8989
assignFiberPropertiesInDEV,
9090
} from './ReactFiber.new';
91+
import {isRootDehydrated} from './ReactFiberShellHydration';
9192
import {NoMode, ProfileMode, ConcurrentMode} from './ReactTypeOfMode';
9293
import {
9394
HostRoot,
@@ -581,7 +582,7 @@ export function scheduleUpdateOnFiber(
581582
}
582583
}
583584

584-
if (root.isDehydrated && root.tag !== LegacyRoot) {
585+
if (isRootDehydrated(root) && root.tag !== LegacyRoot) {
585586
// This root's shell hasn't hydrated yet. Revert to client rendering.
586587
if (workInProgressRoot === root) {
587588
// If this happened during an interleaved event, interrupt the
@@ -1016,7 +1017,7 @@ function performConcurrentWorkOnRoot(root, didTimeout) {
10161017
function recoverFromConcurrentError(root, errorRetryLanes) {
10171018
// If an error occurred during hydration, discard server response and fall
10181019
// back to client side render.
1019-
if (root.isDehydrated) {
1020+
if (isRootDehydrated(root)) {
10201021
root.isDehydrated = false;
10211022
if (__DEV__) {
10221023
errorHydratingContainer(root.containerInfo);

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import {
8888
createWorkInProgress,
8989
assignFiberPropertiesInDEV,
9090
} from './ReactFiber.old';
91+
import {isRootDehydrated} from './ReactFiberShellHydration';
9192
import {NoMode, ProfileMode, ConcurrentMode} from './ReactTypeOfMode';
9293
import {
9394
HostRoot,
@@ -581,7 +582,7 @@ export function scheduleUpdateOnFiber(
581582
}
582583
}
583584

584-
if (root.isDehydrated && root.tag !== LegacyRoot) {
585+
if (isRootDehydrated(root) && root.tag !== LegacyRoot) {
585586
// This root's shell hasn't hydrated yet. Revert to client rendering.
586587
if (workInProgressRoot === root) {
587588
// If this happened during an interleaved event, interrupt the
@@ -1016,7 +1017,7 @@ function performConcurrentWorkOnRoot(root, didTimeout) {
10161017
function recoverFromConcurrentError(root, errorRetryLanes) {
10171018
// If an error occurred during hydration, discard server response and fall
10181019
// back to client side render.
1019-
if (root.isDehydrated) {
1020+
if (isRootDehydrated(root)) {
10201021
root.isDehydrated = false;
10211022
if (__DEV__) {
10221023
errorHydratingContainer(root.containerInfo);

0 commit comments

Comments
 (0)