Skip to content

Commit

Permalink
Compute props diff in the begin phase
Browse files Browse the repository at this point in the history
Otherwise we won't have diffs of parent props when a child later throws.
  • Loading branch information
sebmarkbage committed Mar 7, 2024
1 parent e14532f commit f3704ea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
59 changes: 41 additions & 18 deletions packages/react-reconciler/src/ReactFiberHydrationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ function warnNonHydratedInstance(
}
}

function tryHydrateInstance(fiber: Fiber, nextInstance: any) {
function tryHydrateInstance(
fiber: Fiber,
nextInstance: any,
hostContext: HostContext,
) {
// fiber is a HostComponent Fiber
const instance = canHydrateInstance(
nextInstance,
Expand All @@ -237,6 +241,22 @@ function tryHydrateInstance(fiber: Fiber, nextInstance: any) {
);
if (instance !== null) {
fiber.stateNode = (instance: Instance);

if (__DEV__) {
if (!didSuspendOrErrorDEV) {
const differences = diffHydratedPropsForDevWarnings(
instance,
fiber.type,
fiber.pendingProps,
hostContext,
);
if (differences !== null) {
const diffNode = buildHydrationDiffNode(fiber, 0);
diffNode.serverProps = differences;
}
}
}

hydrationParentFiber = fiber;
nextHydratableInstance = getFirstHydratableChild(instance);
rootOrSingletonContext = false;
Expand Down Expand Up @@ -334,6 +354,22 @@ function claimHydratableSingleton(fiber: Fiber): void {
currentHostContext,
false,
));

if (__DEV__) {
if (!didSuspendOrErrorDEV) {
const differences = diffHydratedPropsForDevWarnings(
instance,
fiber.type,
fiber.pendingProps,
currentHostContext,
);
if (differences !== null) {
const diffNode = buildHydrationDiffNode(fiber, 0);
diffNode.serverProps = differences;
}
}
}

hydrationParentFiber = fiber;
rootOrSingletonContext = true;
nextHydratableInstance = getFirstHydratableChild(instance);
Expand All @@ -354,7 +390,10 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void {
);

const nextInstance = nextHydratableInstance;
if (!nextInstance || !tryHydrateInstance(fiber, nextInstance)) {
if (
!nextInstance ||
!tryHydrateInstance(fiber, nextInstance, currentHostContext)
) {
if (shouldKeepWarning) {
warnNonHydratedInstance(fiber, nextInstance);
}
Expand Down Expand Up @@ -433,22 +472,6 @@ function prepareToHydrateHostInstance(
}

const instance: Instance = fiber.stateNode;
if (__DEV__) {
const shouldWarnIfMismatchDev = !didSuspendOrErrorDEV;
if (shouldWarnIfMismatchDev) {
const differences = diffHydratedPropsForDevWarnings(
instance,
fiber.type,
fiber.memoizedProps,
hostContext,
);
if (differences !== null) {
const diffNode = buildHydrationDiffNode(fiber, 0);
diffNode.serverProps = differences;
}
}
}

const didHydrate = hydrateInstance(
instance,
fiber.type,
Expand Down
1 change: 0 additions & 1 deletion packages/react-reconciler/src/ReactFiberHydrationDiffs.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ function describeCollapsedElement(
content += ' ' + propName + '=' + propValue;
}

// No properties
return indentation(indent) + '<' + type + content + '>\n';
}

Expand Down

0 comments on commit f3704ea

Please sign in to comment.