Skip to content

Commit

Permalink
Mark hydration as suspending on every thrownException
Browse files Browse the repository at this point in the history
previously hydration would only be marked as supsending when a genuine error was thrown. This created an opportunity for a hydration mismatch that would warn after which later hydration mismatches would not lead to warnings. By moving the marker check earlier in the thrownException function we get the hydration context to enter the didSuspend state on both error and thrown promise cases which eliminates this gap.
  • Loading branch information
gnoff committed Apr 20, 2022
1 parent a966eda commit 99da28b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/react-reconciler/src/ReactFiberThrow.new.js
Expand Up @@ -444,6 +444,10 @@ function throwException(
}
}

if (getIsHydrating() && sourceFiber.mode & ConcurrentMode) {
markDidSuspendWhileHydratingDEV();
}

if (
value !== null &&
typeof value === 'object' &&
Expand Down Expand Up @@ -514,8 +518,6 @@ function throwException(
} else {
// This is a regular error, not a Suspense wakeable.
if (getIsHydrating() && sourceFiber.mode & ConcurrentMode) {
markDidSuspendWhileHydratingDEV();

const suspenseBoundary = getNearestSuspenseBoundaryToCapture(returnFiber);
// If the error was thrown during hydration, we may be able to recover by
// discarding the dehydrated content and switching to a client render.
Expand Down
6 changes: 4 additions & 2 deletions packages/react-reconciler/src/ReactFiberThrow.old.js
Expand Up @@ -444,6 +444,10 @@ function throwException(
}
}

if (getIsHydrating() && sourceFiber.mode & ConcurrentMode) {
markDidSuspendWhileHydratingDEV();
}

if (
value !== null &&
typeof value === 'object' &&
Expand Down Expand Up @@ -514,8 +518,6 @@ function throwException(
} else {
// This is a regular error, not a Suspense wakeable.
if (getIsHydrating() && sourceFiber.mode & ConcurrentMode) {
markDidSuspendWhileHydratingDEV();

const suspenseBoundary = getNearestSuspenseBoundaryToCapture(returnFiber);
// If the error was thrown during hydration, we may be able to recover by
// discarding the dehydrated content and switching to a client render.
Expand Down

0 comments on commit 99da28b

Please sign in to comment.