Skip to content

Commit

Permalink
Bugfix: Remove extra render pass when reverting to client render (#26445
Browse files Browse the repository at this point in the history
)

(This was reviewed and approved as part of #26380; I'm extracting it
into its own PR so that it can bisected later if it causes an issue.)

I noticed while working on a PR that when an error happens during
hydration, and we revert to client rendering, React actually does _two_
additional render passes instead of just one. We didn't notice it
earlier because none of our tests happened to assert on how many renders
it took to recover, only on the final output.

It's possible this extra render pass had other consequences that I'm not
aware of, like messing with some assumption in the recoverable errors
logic.

This adds a test to demonstrate the issue. (One problem is that we don't
have much test coverage of this scenario in the first place, which
likely would have caught this earlier.)

DiffTrain build for commit 77ba161.
  • Loading branch information
acdlite committed Mar 21, 2023
1 parent 7d0009a commit 8df739c
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15116,7 +15116,7 @@ function completeWork(current, workInProgress, renderLanes) {
);

if (!fallthroughToNormalSuspensePath) {
if (workInProgress.flags & ShouldCapture) {
if (workInProgress.flags & ForceClientRender) {
// Special case. There were remaining unhydrated nodes. We treat
// this as a mismatch. Revert to client rendering.
return workInProgress;
Expand Down Expand Up @@ -23588,7 +23588,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-520f7f3ed-20230320";
var ReactVersion = "18.3.0-next-77ba1618a-20230320";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4507,7 +4507,7 @@ function completeWork(current, workInProgress, renderLanes) {
null !== hydrationErrors &&
(queueRecoverableErrors(hydrationErrors), (hydrationErrors = null)),
(index = !0);
if (!index) return workInProgress.flags & 65536 ? workInProgress : null;
if (!index) return workInProgress.flags & 256 ? workInProgress : null;
}
if (0 !== (workInProgress.flags & 128))
return (workInProgress.lanes = renderLanes), workInProgress;
Expand Down Expand Up @@ -8561,7 +8561,7 @@ var devToolsConfig$jscomp$inline_1013 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-520f7f3ed-20230320",
version: "18.3.0-next-77ba1618a-20230320",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1201 = {
Expand Down Expand Up @@ -8592,7 +8592,7 @@ var internals$jscomp$inline_1201 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-520f7f3ed-20230320"
reconcilerVersion: "18.3.0-next-77ba1618a-20230320"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1202 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4650,7 +4650,7 @@ function completeWork(current, workInProgress, renderLanes) {
null !== hydrationErrors &&
(queueRecoverableErrors(hydrationErrors), (hydrationErrors = null)),
(index = !0);
if (!index) return workInProgress.flags & 65536 ? workInProgress : null;
if (!index) return workInProgress.flags & 256 ? workInProgress : null;
}
if (0 !== (workInProgress.flags & 128))
return (
Expand Down Expand Up @@ -8988,7 +8988,7 @@ var devToolsConfig$jscomp$inline_1054 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-520f7f3ed-20230320",
version: "18.3.0-next-77ba1618a-20230320",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1240 = {
Expand Down Expand Up @@ -9019,7 +9019,7 @@ var internals$jscomp$inline_1240 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-520f7f3ed-20230320"
reconcilerVersion: "18.3.0-next-77ba1618a-20230320"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1241 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-next-520f7f3ed-20230320";
var ReactVersion = "18.3.0-next-77ba1618a-20230320";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-520f7f3ed-20230320";
exports.version = "18.3.0-next-77ba1618a-20230320";
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-520f7f3ed-20230320";
exports.version = "18.3.0-next-77ba1618a-20230320";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18687,7 +18687,7 @@ function completeWork(current, workInProgress, renderLanes) {
);

if (!fallthroughToNormalSuspensePath) {
if (workInProgress.flags & ShouldCapture) {
if (workInProgress.flags & ForceClientRender) {
// Special case. There were remaining unhydrated nodes. We treat
// this as a mismatch. Revert to client rendering.
return workInProgress;
Expand Down Expand Up @@ -26342,7 +26342,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-520f7f3ed-20230320";
var ReactVersion = "18.3.0-next-77ba1618a-20230320";

function createPortal$1(
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5837,7 +5837,7 @@ function completeWork(current, workInProgress, renderLanes) {
(queueRecoverableErrors(hydrationErrors), (hydrationErrors = null)),
(currentInstance = !0);
if (!currentInstance)
return workInProgress.flags & 65536 ? workInProgress : null;
return workInProgress.flags & 256 ? workInProgress : null;
}
if (0 !== (workInProgress.flags & 128))
return (workInProgress.lanes = renderLanes), workInProgress;
Expand Down Expand Up @@ -9496,7 +9496,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1033 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-next-520f7f3ed-20230320",
version: "18.3.0-next-77ba1618a-20230320",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -9538,7 +9538,7 @@ var internals$jscomp$inline_1276 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-520f7f3ed-20230320"
reconcilerVersion: "18.3.0-next-77ba1618a-20230320"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1277 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6107,7 +6107,7 @@ function completeWork(current, workInProgress, renderLanes) {
(queueRecoverableErrors(hydrationErrors), (hydrationErrors = null)),
(currentInstance = !0);
if (!currentInstance)
return workInProgress.flags & 65536 ? workInProgress : null;
return workInProgress.flags & 256 ? workInProgress : null;
}
if (0 !== (workInProgress.flags & 128))
return (
Expand Down Expand Up @@ -10206,7 +10206,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1110 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-next-520f7f3ed-20230320",
version: "18.3.0-next-77ba1618a-20230320",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -10261,7 +10261,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-520f7f3ed-20230320"
reconcilerVersion: "18.3.0-next-77ba1618a-20230320"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19347,7 +19347,7 @@ function completeWork(current, workInProgress, renderLanes) {
);

if (!fallthroughToNormalSuspensePath) {
if (workInProgress.flags & ShouldCapture) {
if (workInProgress.flags & ForceClientRender) {
// Special case. There were remaining unhydrated nodes. We treat
// this as a mismatch. Revert to client rendering.
return workInProgress;
Expand Down Expand Up @@ -27393,7 +27393,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-520f7f3ed-20230320";
var ReactVersion = "18.3.0-next-77ba1618a-20230320";

function createPortal$1(
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5960,7 +5960,7 @@ function completeWork(current, workInProgress, renderLanes) {
null !== hydrationErrors &&
(queueRecoverableErrors(hydrationErrors), (hydrationErrors = null)),
(type = !0);
if (!type) return workInProgress.flags & 65536 ? workInProgress : null;
if (!type) return workInProgress.flags & 256 ? workInProgress : null;
}
if (0 !== (workInProgress.flags & 128))
return (workInProgress.lanes = renderLanes), workInProgress;
Expand Down Expand Up @@ -9685,7 +9685,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1095 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-520f7f3ed-20230320",
version: "18.3.0-next-77ba1618a-20230320",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -9727,7 +9727,7 @@ var internals$jscomp$inline_1345 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-520f7f3ed-20230320"
reconcilerVersion: "18.3.0-next-77ba1618a-20230320"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1346 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6229,7 +6229,7 @@ function completeWork(current, workInProgress, renderLanes) {
null !== hydrationErrors &&
(queueRecoverableErrors(hydrationErrors), (hydrationErrors = null)),
(type = !0);
if (!type) return workInProgress.flags & 65536 ? workInProgress : null;
if (!type) return workInProgress.flags & 256 ? workInProgress : null;
}
if (0 !== (workInProgress.flags & 128))
return (
Expand Down Expand Up @@ -10395,7 +10395,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1172 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-520f7f3ed-20230320",
version: "18.3.0-next-77ba1618a-20230320",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -10450,7 +10450,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-520f7f3ed-20230320"
reconcilerVersion: "18.3.0-next-77ba1618a-20230320"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
computeComponentStackForErrorReporting: function (reactTag) {
Expand Down

0 comments on commit 8df739c

Please sign in to comment.