Skip to content

Commit c09fe9e

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 e14532f commit c09fe9e

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

packages/react-reconciler/src/ReactFiberHydrationContext.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ function warnNonHydratedInstance(
227227
}
228228
}
229229

230-
function tryHydrateInstance(fiber: Fiber, nextInstance: any) {
230+
function tryHydrateInstance(
231+
fiber: Fiber,
232+
nextInstance: any,
233+
hostContext: HostContext,
234+
) {
231235
// fiber is a HostComponent Fiber
232236
const instance = canHydrateInstance(
233237
nextInstance,
@@ -237,6 +241,23 @@ function tryHydrateInstance(fiber: Fiber, nextInstance: any) {
237241
);
238242
if (instance !== null) {
239243
fiber.stateNode = (instance: Instance);
244+
245+
if (__DEV__) {
246+
const shouldWarnIfMismatchDev = !didSuspendOrErrorDEV;
247+
if (shouldWarnIfMismatchDev) {
248+
const differences = diffHydratedPropsForDevWarnings(
249+
instance,
250+
fiber.type,
251+
fiber.pendingProps,
252+
hostContext,
253+
);
254+
if (differences !== null) {
255+
const diffNode = buildHydrationDiffNode(fiber, 0);
256+
diffNode.serverProps = differences;
257+
}
258+
}
259+
}
260+
240261
hydrationParentFiber = fiber;
241262
nextHydratableInstance = getFirstHydratableChild(instance);
242263
rootOrSingletonContext = false;
@@ -354,7 +375,10 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void {
354375
);
355376

356377
const nextInstance = nextHydratableInstance;
357-
if (!nextInstance || !tryHydrateInstance(fiber, nextInstance)) {
378+
if (
379+
!nextInstance ||
380+
!tryHydrateInstance(fiber, nextInstance, currentHostContext)
381+
) {
358382
if (shouldKeepWarning) {
359383
warnNonHydratedInstance(fiber, nextInstance);
360384
}
@@ -433,22 +457,6 @@ function prepareToHydrateHostInstance(
433457
}
434458

435459
const instance: Instance = fiber.stateNode;
436-
if (__DEV__) {
437-
const shouldWarnIfMismatchDev = !didSuspendOrErrorDEV;
438-
if (shouldWarnIfMismatchDev) {
439-
const differences = diffHydratedPropsForDevWarnings(
440-
instance,
441-
fiber.type,
442-
fiber.memoizedProps,
443-
hostContext,
444-
);
445-
if (differences !== null) {
446-
const diffNode = buildHydrationDiffNode(fiber, 0);
447-
diffNode.serverProps = differences;
448-
}
449-
}
450-
}
451-
452460
const didHydrate = hydrateInstance(
453461
instance,
454462
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)