Skip to content

Commit

Permalink
warn in a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
salazarm committed Feb 1, 2022
1 parent 52ac465 commit 3ae3605
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
29 changes: 19 additions & 10 deletions packages/react-reconciler/src/ReactFiberHydrationContext.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,16 @@ function tryHydrate(fiber, nextInstance) {
}
}

function throwOnHydrationMismatchIfConcurrentMode(fiber: Fiber) {
if (
function shouldClientRenderOnMismatch(fiber: Fiber) {
return (
enableClientRenderFallbackOnHydrationMismatch &&
(fiber.mode & ConcurrentMode) !== NoMode &&
(fiber.flags & DidCapture) === NoFlags
) {
);
}

function throwOnHydrationMismatchIfConcurrentMode(fiber: Fiber) {
if (shouldClientRenderOnMismatch(fiber)) {
throw new Error(
'An error occurred during hydration. The server HTML was replaced with client content',
);
Expand Down Expand Up @@ -553,11 +557,14 @@ function popHydrationState(fiber: Fiber): boolean {
) {
let nextInstance = nextHydratableInstance;
if (nextInstance) {
warnIfUnhydratedTailNodes(fiber);
throwOnHydrationMismatchIfConcurrentMode(fiber);
while (nextInstance) {
deleteHydratableInstance(fiber, nextInstance);
nextInstance = getNextHydratableSibling(nextInstance);
if (shouldClientRenderOnMismatch(fiber)) {
warnIfUnhydratedTailNodes(fiber);
throwOnHydrationMismatchIfConcurrentMode(fiber);
} else {
while (nextInstance) {
deleteHydratableInstance(fiber, nextInstance);
nextInstance = getNextHydratableSibling(nextInstance);
}
}
}
}
Expand All @@ -577,8 +584,10 @@ function hasUnhydratedTailNodes() {
}

function warnIfUnhydratedTailNodes(fiber: Fiber) {
if (nextHydratableInstance) {
warnUnhydratedInstance(fiber, nextHydratableInstance);
let nextInstance = nextHydratableInstance;
while (nextInstance) {
warnUnhydratedInstance(fiber, nextInstance);
nextInstance = getNextHydratableSibling(nextInstance);
}
}

Expand Down
29 changes: 19 additions & 10 deletions packages/react-reconciler/src/ReactFiberHydrationContext.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,16 @@ function tryHydrate(fiber, nextInstance) {
}
}

function throwOnHydrationMismatchIfConcurrentMode(fiber: Fiber) {
if (
function shouldClientRenderOnMismatch(fiber: Fiber) {
return (
enableClientRenderFallbackOnHydrationMismatch &&
(fiber.mode & ConcurrentMode) !== NoMode &&
(fiber.flags & DidCapture) === NoFlags
) {
);
}

function throwOnHydrationMismatchIfConcurrentMode(fiber: Fiber) {
if (shouldClientRenderOnMismatch(fiber)) {
throw new Error(
'An error occurred during hydration. The server HTML was replaced with client content',
);
Expand Down Expand Up @@ -553,11 +557,14 @@ function popHydrationState(fiber: Fiber): boolean {
) {
let nextInstance = nextHydratableInstance;
if (nextInstance) {
warnIfUnhydratedTailNodes(fiber);
throwOnHydrationMismatchIfConcurrentMode(fiber);
while (nextInstance) {
deleteHydratableInstance(fiber, nextInstance);
nextInstance = getNextHydratableSibling(nextInstance);
if (shouldClientRenderOnMismatch(fiber)) {
warnIfUnhydratedTailNodes(fiber);
throwOnHydrationMismatchIfConcurrentMode(fiber);
} else {
while (nextInstance) {
deleteHydratableInstance(fiber, nextInstance);
nextInstance = getNextHydratableSibling(nextInstance);
}
}
}
}
Expand All @@ -577,8 +584,10 @@ function hasUnhydratedTailNodes() {
}

function warnIfUnhydratedTailNodes(fiber: Fiber) {
if (nextHydratableInstance) {
warnUnhydratedInstance(fiber, nextHydratableInstance);
let nextInstance = nextHydratableInstance;
while (nextInstance) {
warnUnhydratedInstance(fiber, nextInstance);
nextInstance = getNextHydratableSibling(nextInstance);
}
}

Expand Down

0 comments on commit 3ae3605

Please sign in to comment.