Skip to content

Commit

Permalink
[Fiber] Create virtual Fiber when an error occurs during reconcilation (
Browse files Browse the repository at this point in the history
#29804)

This lets us rethrow it in the conceptual place of the child.

There's currently a problem when we suspend or throw in the child fiber
reconciliation phase. This work is done by the parent component, so if
it suspends or errors it is as if that component errored or suspended.
However, conceptually it's like a child suspended or errored.

In theory any thing can throw but it is really mainly due to either
`React.lazy` (both in the element.type position and node position),
`Thenable`s or the `Thenable`s that make up `AsyncIterable`s.

Mainly this happens because a Server Component that errors turns into a
`React.lazy`. In practice this means that if you have a Server Component
as the direct child of an Error Boundary. Errors inside of it won't be
caught.

We used to have the same problem with Thenables and Suspense but because
it's now always nested inside an inner Offscreen boundary that shields
it by being one level nested. However, when we have raw Offscreen
(Activity) boundaries they should also be able to catch the suspense if
it's in a hidden state so the problem returns. This fixes it for thrown
promises but it doesn't fix it for SuspenseException. I'm not sure this
is even the right strategy for Suspense though. It kind of relies on the
node never actually mounting/committing.

It's conceptually a little tricky because the current component can
inspect the children and make decisions based on them. Such as
SuspenseList.

The other thing that this PR tries to address is that it sets the
foundation for dealing with error reporting for Server Components that
errored. If something client side errors it'll be a stack like Server
(DebugInfo) -> Fiber -> Fiber -> Server -> (DebugInfo) -> Fiber.
However, all error reporting relies on it eventually terminating into a
Fiber that is responsible for the error. To avoid having to fork too
much it would be nice if I could create a Fiber to associate with the
error so that even a Server component error in this case ultimately
terminates in a Fiber.

DiffTrain build for [270229f](270229f)
  • Loading branch information
sebmarkbage committed Jun 11, 2024
1 parent fe0295a commit 5ad4e79
Show file tree
Hide file tree
Showing 34 changed files with 1,516 additions and 1,198 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
01a40570c3cd852593c9bc88978b11cb9a2c5720
270229f0c337dc652f07ef27d2254bb922bfaa9e
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
01a40570c3cd852593c9bc88978b11cb9a2c5720
270229f0c337dc652f07ef27d2254bb922bfaa9e
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-classic-01a40570c3-20240611";
exports.version = "19.0.0-www-classic-270229f0c3-20240611";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-modern-01a40570c3-20240611";
exports.version = "19.0.0-www-modern-270229f0c3-20240611";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
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 @@ -665,4 +665,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-01a40570c3-20240611";
exports.version = "19.0.0-www-classic-270229f0c3-20240611";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-01a40570c3-20240611";
exports.version = "19.0.0-www-modern-270229f0c3-20240611";
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 @@ -669,7 +669,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-01a40570c3-20240611";
exports.version = "19.0.0-www-classic-270229f0c3-20240611";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-01a40570c3-20240611";
exports.version = "19.0.0-www-modern-270229f0c3-20240611";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
45 changes: 33 additions & 12 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3842,16 +3842,32 @@ __DEV__ &&
return deleteRemainingChildren(returnFiber, currentFirstChild);
}
return function (returnFiber, currentFirstChild, newChild, lanes) {
thenableIndexCounter$1 = 0;
returnFiber = reconcileChildFibersImpl(
returnFiber,
currentFirstChild,
newChild,
lanes,
null
);
thenableState$1 = null;
return returnFiber;
try {
thenableIndexCounter$1 = 0;
var firstChildFiber = reconcileChildFibersImpl(
returnFiber,
currentFirstChild,
newChild,
lanes,
null
);
thenableState$1 = null;
return firstChildFiber;
} catch (x) {
if (
x === SuspenseException ||
(!disableLegacyMode &&
0 === (returnFiber.mode & 1) &&
"object" === typeof x &&
null !== x &&
"function" === typeof x.then)
)
throw x;
currentFirstChild = createFiber(29, x, null, returnFiber.mode);
currentFirstChild.lanes = lanes;
currentFirstChild.return = returnFiber;
return currentFirstChild;
}
};
}
function pushHiddenContext(fiber, context) {
Expand Down Expand Up @@ -8575,6 +8591,9 @@ __DEV__ &&
: (workInProgress = null),
workInProgress
);
break;
case 29:
throw workInProgress.pendingProps;
}
throw Error(
"Unknown unit of work tag (" +
Expand Down Expand Up @@ -9588,6 +9607,8 @@ __DEV__ &&
bubbleProperties(workInProgress)),
null
);
case 29:
if (!disableLegacyMode) return null;
}
throw Error(
"Unknown unit of work tag (" +
Expand Down Expand Up @@ -16922,14 +16943,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-classic-01a40570c3-20240611"
reconcilerVersion: "19.0.0-www-classic-270229f0c3-20240611"
});
})({
findFiberByHostInstance: function () {
return null;
},
bundleType: 1,
version: "19.0.0-www-classic-01a40570c3-20240611",
version: "19.0.0-www-classic-270229f0c3-20240611",
rendererPackageName: "react-art"
});
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,
Expand Down
35 changes: 23 additions & 12 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -3741,16 +3741,24 @@ __DEV__ &&
return deleteRemainingChildren(returnFiber, currentFirstChild);
}
return function (returnFiber, currentFirstChild, newChild, lanes) {
thenableIndexCounter$1 = 0;
returnFiber = reconcileChildFibersImpl(
returnFiber,
currentFirstChild,
newChild,
lanes,
null
);
thenableState$1 = null;
return returnFiber;
try {
thenableIndexCounter$1 = 0;
var firstChildFiber = reconcileChildFibersImpl(
returnFiber,
currentFirstChild,
newChild,
lanes,
null
);
thenableState$1 = null;
return firstChildFiber;
} catch (x) {
if (x === SuspenseException) throw x;
currentFirstChild = createFiber(29, x, null, returnFiber.mode);
currentFirstChild.lanes = lanes;
currentFirstChild.return = returnFiber;
return currentFirstChild;
}
};
}
function pushHiddenContext(fiber, context) {
Expand Down Expand Up @@ -8265,6 +8273,9 @@ __DEV__ &&
: (workInProgress = null),
workInProgress
);
break;
case 29:
throw workInProgress.pendingProps;
}
throw Error(
"Unknown unit of work tag (" +
Expand Down Expand Up @@ -16362,14 +16373,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-modern-01a40570c3-20240611"
reconcilerVersion: "19.0.0-www-modern-270229f0c3-20240611"
});
})({
findFiberByHostInstance: function () {
return null;
},
bundleType: 1,
version: "19.0.0-www-modern-01a40570c3-20240611",
version: "19.0.0-www-modern-270229f0c3-20240611",
rendererPackageName: "react-art"
});
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,
Expand Down
70 changes: 46 additions & 24 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2454,15 +2454,32 @@ function createChildReconciler(shouldTrackSideEffects) {
: deleteRemainingChildren(returnFiber, currentFirstChild);
}
return function (returnFiber, currentFirstChild, newChild, lanes) {
thenableIndexCounter$1 = 0;
returnFiber = reconcileChildFibersImpl(
returnFiber,
currentFirstChild,
newChild,
lanes
);
thenableState$1 = null;
return returnFiber;
try {
thenableIndexCounter$1 = 0;
var firstChildFiber = reconcileChildFibersImpl(
returnFiber,
currentFirstChild,
newChild,
lanes,
null
);
thenableState$1 = null;
return firstChildFiber;
} catch (x) {
if (
x === SuspenseException ||
(!disableLegacyMode &&
0 === (returnFiber.mode & 1) &&
"object" === typeof x &&
null !== x &&
"function" === typeof x.then)
)
throw x;
currentFirstChild = createFiber(29, x, null, returnFiber.mode);
currentFirstChild.lanes = lanes;
currentFirstChild.return = returnFiber;
return currentFirstChild;
}
};
}
var reconcileChildFibers = createChildReconciler(!0),
Expand Down Expand Up @@ -6105,6 +6122,9 @@ function beginWork(current, workInProgress, renderLanes) {
: (workInProgress = null),
workInProgress
);
break;
case 29:
throw workInProgress.pendingProps;
}
throw Error(formatProdErrorMessage(156, workInProgress.tag));
}
Expand Down Expand Up @@ -6968,6 +6988,8 @@ function completeWork(current, workInProgress, renderLanes) {
bubbleProperties(workInProgress)),
null
);
case 29:
if (!disableLegacyMode) return null;
}
throw Error(formatProdErrorMessage(156, workInProgress.tag));
}
Expand Down Expand Up @@ -10681,19 +10703,19 @@ var slice = Array.prototype.slice,
};
return Text;
})(React.Component),
devToolsConfig$jscomp$inline_1159 = {
devToolsConfig$jscomp$inline_1165 = {
findFiberByHostInstance: function () {
return null;
},
bundleType: 0,
version: "19.0.0-www-classic-01a40570c3-20240611",
version: "19.0.0-www-classic-270229f0c3-20240611",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1371 = {
bundleType: devToolsConfig$jscomp$inline_1159.bundleType,
version: devToolsConfig$jscomp$inline_1159.version,
rendererPackageName: devToolsConfig$jscomp$inline_1159.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1159.rendererConfig,
var internals$jscomp$inline_1377 = {
bundleType: devToolsConfig$jscomp$inline_1165.bundleType,
version: devToolsConfig$jscomp$inline_1165.version,
rendererPackageName: devToolsConfig$jscomp$inline_1165.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1165.rendererConfig,
overrideHookState: null,
overrideHookStateDeletePath: null,
overrideHookStateRenamePath: null,
Expand All @@ -10710,26 +10732,26 @@ var internals$jscomp$inline_1371 = {
return null === fiber ? null : fiber.stateNode;
},
findFiberByHostInstance:
devToolsConfig$jscomp$inline_1159.findFiberByHostInstance ||
devToolsConfig$jscomp$inline_1165.findFiberByHostInstance ||
emptyFindFiberByHostInstance,
findHostInstancesForRefresh: null,
scheduleRefresh: null,
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-classic-01a40570c3-20240611"
reconcilerVersion: "19.0.0-www-classic-270229f0c3-20240611"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1372 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
var hook$jscomp$inline_1378 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
if (
!hook$jscomp$inline_1372.isDisabled &&
hook$jscomp$inline_1372.supportsFiber
!hook$jscomp$inline_1378.isDisabled &&
hook$jscomp$inline_1378.supportsFiber
)
try {
(rendererID = hook$jscomp$inline_1372.inject(
internals$jscomp$inline_1371
(rendererID = hook$jscomp$inline_1378.inject(
internals$jscomp$inline_1377
)),
(injectedHook = hook$jscomp$inline_1372);
(injectedHook = hook$jscomp$inline_1378);
} catch (err) {}
}
var Path = Mode$1.Path;
Expand Down
Loading

0 comments on commit 5ad4e79

Please sign in to comment.