Skip to content

Commit 69263c6

Browse files
committed
Compute props diff in the begin phase
Otherwise we won't have diffs of parent props when a child later throws.
1 parent 06edfe8 commit 69263c6

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

packages/react-reconciler/src/ReactFiberHydrationContext.js

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ function warnNonHydratedInstance(
220220
}
221221
}
222222

223-
function tryHydrateInstance(fiber: Fiber, nextInstance: any) {
223+
function tryHydrateInstance(
224+
fiber: Fiber,
225+
nextInstance: any,
226+
hostContext: HostContext,
227+
) {
224228
// fiber is a HostComponent Fiber
225229
const instance = canHydrateInstance(
226230
nextInstance,
@@ -230,6 +234,22 @@ function tryHydrateInstance(fiber: Fiber, nextInstance: any) {
230234
);
231235
if (instance !== null) {
232236
fiber.stateNode = (instance: Instance);
237+
238+
if (__DEV__) {
239+
if (!didSuspendOrErrorDEV) {
240+
const differences = diffHydratedPropsForDevWarnings(
241+
instance,
242+
fiber.type,
243+
fiber.pendingProps,
244+
hostContext,
245+
);
246+
if (differences !== null) {
247+
const diffNode = buildHydrationDiffNode(fiber, 0);
248+
diffNode.serverProps = differences;
249+
}
250+
}
251+
}
252+
233253
hydrationParentFiber = fiber;
234254
nextHydratableInstance = getFirstHydratableChild(instance);
235255
rootOrSingletonContext = false;
@@ -327,6 +347,22 @@ function claimHydratableSingleton(fiber: Fiber): void {
327347
currentHostContext,
328348
false,
329349
));
350+
351+
if (__DEV__) {
352+
if (!didSuspendOrErrorDEV) {
353+
const differences = diffHydratedPropsForDevWarnings(
354+
instance,
355+
fiber.type,
356+
fiber.pendingProps,
357+
currentHostContext,
358+
);
359+
if (differences !== null) {
360+
const diffNode = buildHydrationDiffNode(fiber, 0);
361+
diffNode.serverProps = differences;
362+
}
363+
}
364+
}
365+
330366
hydrationParentFiber = fiber;
331367
rootOrSingletonContext = true;
332368
nextHydratableInstance = getFirstHydratableChild(instance);
@@ -347,7 +383,10 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void {
347383
);
348384

349385
const nextInstance = nextHydratableInstance;
350-
if (!nextInstance || !tryHydrateInstance(fiber, nextInstance)) {
386+
if (
387+
!nextInstance ||
388+
!tryHydrateInstance(fiber, nextInstance, currentHostContext)
389+
) {
351390
if (shouldKeepWarning) {
352391
warnNonHydratedInstance(fiber, nextInstance);
353392
}
@@ -426,22 +465,6 @@ function prepareToHydrateHostInstance(
426465
}
427466

428467
const instance: Instance = fiber.stateNode;
429-
if (__DEV__) {
430-
const shouldWarnIfMismatchDev = !didSuspendOrErrorDEV;
431-
if (shouldWarnIfMismatchDev) {
432-
const differences = diffHydratedPropsForDevWarnings(
433-
instance,
434-
fiber.type,
435-
fiber.memoizedProps,
436-
hostContext,
437-
);
438-
if (differences !== null) {
439-
const diffNode = buildHydrationDiffNode(fiber, 0);
440-
diffNode.serverProps = differences;
441-
}
442-
}
443-
}
444-
445468
const didHydrate = hydrateInstance(
446469
instance,
447470
fiber.type,

packages/react-reconciler/src/ReactFiberHydrationDiffs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ function describeCollapsedElement(
279279
content += ' ' + propName + '=' + propValue;
280280
}
281281

282-
// No properties
283282
return indentation(indent) + '<' + type + content + '>\n';
284283
}
285284

0 commit comments

Comments
 (0)