Skip to content

Commit

Permalink
Move tail hydration mismatch back to hydration context (#28501)
Browse files Browse the repository at this point in the history
In #23176 we added a special case in completeWork for SuspenseBoundaries
if they still have trailing children. However, that misses a case
because it doesn't log a recoverable error for the hydration mismatch.
So we get an error that we rerendered.

I think this special case was done to avoid contexts getting out of
sync. I don't know why we didn't just move where the pop happens though
so that's what I did here and let the regular pass throw instead. Seems
to be pass the tests.

DiffTrain build for [c11b196](c11b196)
  • Loading branch information
sebmarkbage committed Mar 6, 2024
1 parent 6cf536e commit 401192f
Show file tree
Hide file tree
Showing 19 changed files with 357 additions and 445 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113ab9af08c46e8a548a397154f5c9dfeb96ab6a
c11b196ae3e2e3c5d143d9102b35a6b6fa97c849
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-www-classic-f938cefa";
exports.version = "18.3.0-www-classic-5741f0db";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-www-classic-c1c1744a";
exports.version = "18.3.0-www-classic-6ddd4df1";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
11 changes: 7 additions & 4 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if (__DEV__) {
return self;
}

var ReactVersion = "18.3.0-www-classic-20a604bc";
var ReactVersion = "18.3.0-www-classic-14143ab0";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -19974,7 +19974,6 @@ if (__DEV__) {
}

case SuspenseComponent: {
popSuspenseHandler(workInProgress);
var nextState = workInProgress.memoizedState; // Special path for dehydrated boundaries. We may eventually move this
// to its own fiber type so that we can add other kinds of hydration
// boundaries that aren't associated with a Suspense tree. In anticipation
Expand All @@ -19995,17 +19994,21 @@ if (__DEV__) {

if (!fallthroughToNormalSuspensePath) {
if (workInProgress.flags & ForceClientRender) {
// Special case. There were remaining unhydrated nodes. We treat
popSuspenseHandler(workInProgress); // Special case. There were remaining unhydrated nodes. We treat
// this as a mismatch. Revert to client rendering.

return workInProgress;
} else {
// Did not finish hydrating, either because this is the initial
popSuspenseHandler(workInProgress); // Did not finish hydrating, either because this is the initial
// render or because something suspended.

return null;
}
} // Continue with the normal Suspense path.
}

popSuspenseHandler(workInProgress);

if ((workInProgress.flags & DidCapture) !== NoFlags$1) {
// Something suspended. Re-render with the fallback children.
workInProgress.lanes = renderLanes; // Do not reset the effect list.
Expand Down
11 changes: 7 additions & 4 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if (__DEV__) {
return self;
}

var ReactVersion = "18.3.0-www-modern-c0bbf979";
var ReactVersion = "18.3.0-www-modern-0883d4be";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -19655,7 +19655,6 @@ if (__DEV__) {
}

case SuspenseComponent: {
popSuspenseHandler(workInProgress);
var nextState = workInProgress.memoizedState; // Special path for dehydrated boundaries. We may eventually move this
// to its own fiber type so that we can add other kinds of hydration
// boundaries that aren't associated with a Suspense tree. In anticipation
Expand All @@ -19676,17 +19675,21 @@ if (__DEV__) {

if (!fallthroughToNormalSuspensePath) {
if (workInProgress.flags & ForceClientRender) {
// Special case. There were remaining unhydrated nodes. We treat
popSuspenseHandler(workInProgress); // Special case. There were remaining unhydrated nodes. We treat
// this as a mismatch. Revert to client rendering.

return workInProgress;
} else {
// Did not finish hydrating, either because this is the initial
popSuspenseHandler(workInProgress); // Did not finish hydrating, either because this is the initial
// render or because something suspended.

return null;
}
} // Continue with the normal Suspense path.
}

popSuspenseHandler(workInProgress);

if ((workInProgress.flags & DidCapture) !== NoFlags$1) {
// Something suspended. Re-render with the fallback children.
workInProgress.lanes = renderLanes; // Do not reset the effect list.
Expand Down
14 changes: 9 additions & 5 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6253,7 +6253,6 @@ function completeWork(current, workInProgress, renderLanes) {
bubbleProperties(workInProgress);
return null;
case 13:
popSuspenseHandler(workInProgress);
newProps = workInProgress.memoizedState;
if (
null === current ||
Expand All @@ -6274,9 +6273,14 @@ function completeWork(current, workInProgress, renderLanes) {
null !== hydrationErrors &&
(queueRecoverableErrors(hydrationErrors), (hydrationErrors = null)),
(instance = !0);
if (!instance)
return workInProgress.flags & 256 ? workInProgress : null;
if (!instance) {
if (workInProgress.flags & 256)
return popSuspenseHandler(workInProgress), workInProgress;
popSuspenseHandler(workInProgress);
return null;
}
}
popSuspenseHandler(workInProgress);
if (0 !== (workInProgress.flags & 128))
return (workInProgress.lanes = renderLanes), workInProgress;
renderLanes = null !== newProps;
Expand Down Expand Up @@ -10596,7 +10600,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-classic-0f4883c5",
version: "18.3.0-www-classic-cad557f7",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1320 = {
Expand Down Expand Up @@ -10627,7 +10631,7 @@ var internals$jscomp$inline_1320 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-0f4883c5"
reconcilerVersion: "18.3.0-www-classic-cad557f7"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1321 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
14 changes: 9 additions & 5 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -5992,7 +5992,6 @@ function completeWork(current, workInProgress, renderLanes) {
bubbleProperties(workInProgress);
return null;
case 13:
popSuspenseHandler(workInProgress);
newProps = workInProgress.memoizedState;
if (
null === current ||
Expand All @@ -6013,9 +6012,14 @@ function completeWork(current, workInProgress, renderLanes) {
null !== hydrationErrors &&
(queueRecoverableErrors(hydrationErrors), (hydrationErrors = null)),
(instance = !0);
if (!instance)
return workInProgress.flags & 256 ? workInProgress : null;
if (!instance) {
if (workInProgress.flags & 256)
return popSuspenseHandler(workInProgress), workInProgress;
popSuspenseHandler(workInProgress);
return null;
}
}
popSuspenseHandler(workInProgress);
if (0 !== (workInProgress.flags & 128))
return (workInProgress.lanes = renderLanes), workInProgress;
renderLanes = null !== newProps;
Expand Down Expand Up @@ -10251,7 +10255,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-1b51d894",
version: "18.3.0-www-modern-5c2d3ed7",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1300 = {
Expand Down Expand Up @@ -10282,7 +10286,7 @@ var internals$jscomp$inline_1300 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-1b51d894"
reconcilerVersion: "18.3.0-www-modern-5c2d3ed7"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1301 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
26 changes: 7 additions & 19 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8941,10 +8941,6 @@ if (__DEV__) {
return true;
}

function hasUnhydratedTailNodes() {
return isHydrating && nextHydratableInstance !== null;
}

function warnIfUnhydratedTailNodes(fiber) {
var nextInstance = nextHydratableInstance;

Expand Down Expand Up @@ -24958,17 +24954,6 @@ if (__DEV__) {
workInProgress,
nextState
) {
if (
hasUnhydratedTailNodes() &&
(workInProgress.mode & ConcurrentMode) !== NoMode &&
(workInProgress.flags & DidCapture) === NoFlags$1
) {
warnIfUnhydratedTailNodes(workInProgress);
resetHydrationState();
workInProgress.flags |= ForceClientRender | DidCapture;
return false;
}

var wasHydrated = popHydrationState(workInProgress);

if (nextState !== null && nextState.dehydrated !== null) {
Expand Down Expand Up @@ -25405,7 +25390,6 @@ if (__DEV__) {
}

case SuspenseComponent: {
popSuspenseHandler(workInProgress);
var nextState = workInProgress.memoizedState; // Special path for dehydrated boundaries. We may eventually move this
// to its own fiber type so that we can add other kinds of hydration
// boundaries that aren't associated with a Suspense tree. In anticipation
Expand All @@ -25426,17 +25410,21 @@ if (__DEV__) {

if (!fallthroughToNormalSuspensePath) {
if (workInProgress.flags & ForceClientRender) {
// Special case. There were remaining unhydrated nodes. We treat
popSuspenseHandler(workInProgress); // Special case. There were remaining unhydrated nodes. We treat
// this as a mismatch. Revert to client rendering.

return workInProgress;
} else {
// Did not finish hydrating, either because this is the initial
popSuspenseHandler(workInProgress); // Did not finish hydrating, either because this is the initial
// render or because something suspended.

return null;
}
} // Continue with the normal Suspense path.
}

popSuspenseHandler(workInProgress);

if ((workInProgress.flags & DidCapture) !== NoFlags$1) {
// Something suspended. Re-render with the fallback children.
workInProgress.lanes = renderLanes; // Do not reset the effect list.
Expand Down Expand Up @@ -36046,7 +36034,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-www-classic-e13660d6";
var ReactVersion = "18.3.0-www-classic-78291ba2";

function createPortal$1(
children,
Expand Down
26 changes: 7 additions & 19 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -8903,10 +8903,6 @@ if (__DEV__) {
return true;
}

function hasUnhydratedTailNodes() {
return isHydrating && nextHydratableInstance !== null;
}

function warnIfUnhydratedTailNodes(fiber) {
var nextInstance = nextHydratableInstance;

Expand Down Expand Up @@ -24843,17 +24839,6 @@ if (__DEV__) {
workInProgress,
nextState
) {
if (
hasUnhydratedTailNodes() &&
(workInProgress.mode & ConcurrentMode) !== NoMode &&
(workInProgress.flags & DidCapture) === NoFlags$1
) {
warnIfUnhydratedTailNodes(workInProgress);
resetHydrationState();
workInProgress.flags |= ForceClientRender | DidCapture;
return false;
}

var wasHydrated = popHydrationState(workInProgress);

if (nextState !== null && nextState.dehydrated !== null) {
Expand Down Expand Up @@ -25283,7 +25268,6 @@ if (__DEV__) {
}

case SuspenseComponent: {
popSuspenseHandler(workInProgress);
var nextState = workInProgress.memoizedState; // Special path for dehydrated boundaries. We may eventually move this
// to its own fiber type so that we can add other kinds of hydration
// boundaries that aren't associated with a Suspense tree. In anticipation
Expand All @@ -25304,17 +25288,21 @@ if (__DEV__) {

if (!fallthroughToNormalSuspensePath) {
if (workInProgress.flags & ForceClientRender) {
// Special case. There were remaining unhydrated nodes. We treat
popSuspenseHandler(workInProgress); // Special case. There were remaining unhydrated nodes. We treat
// this as a mismatch. Revert to client rendering.

return workInProgress;
} else {
// Did not finish hydrating, either because this is the initial
popSuspenseHandler(workInProgress); // Did not finish hydrating, either because this is the initial
// render or because something suspended.

return null;
}
} // Continue with the normal Suspense path.
}

popSuspenseHandler(workInProgress);

if ((workInProgress.flags & DidCapture) !== NoFlags$1) {
// Something suspended. Re-render with the fallback children.
workInProgress.lanes = renderLanes; // Do not reset the effect list.
Expand Down Expand Up @@ -35893,7 +35881,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-www-modern-06a38f42";
var ReactVersion = "18.3.0-www-modern-8a38254f";

function createPortal$1(
children,
Expand Down
Loading

0 comments on commit 401192f

Please sign in to comment.