Skip to content

Commit 4387423

Browse files
committed
Remove invokeGuardedCallback and replay trick (#28515)
We broke the ability to "break on uncaught exceptions" by adding a try/catch higher up in the scheduling. We're giving up on fixing that so we can remove the replay trick inside an event handler. The issue with that approach is that we end up double logging a lot of errors in DEV since they get reported to the page. It's also a lot of complexity around this feature. DiffTrain build for [89021fb](89021fb)
1 parent 7f3682c commit 4387423

23 files changed

+40887
-42979
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
56e20051c3c1611f9495081d01f1946184332c6b
1+
89021fb4ec9aa82194b0788566e736a4cedfc0e4

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-www-classic-7d5d3599";
27+
var ReactVersion = "18.3.0-www-classic-489e33ec";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,4 +633,4 @@ exports.useSyncExternalStore = function (
633633
exports.useTransition = function () {
634634
return ReactCurrentDispatcher.current.useTransition();
635635
};
636-
exports.version = "18.3.0-www-classic-32d29ecb";
636+
exports.version = "18.3.0-www-classic-76e5ebad";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ exports.useSyncExternalStore = function (
637637
exports.useTransition = function () {
638638
return ReactCurrentDispatcher.current.useTransition();
639639
};
640-
exports.version = "18.3.0-www-classic-e14b3ab5";
640+
exports.version = "18.3.0-www-classic-33a06df4";
641641
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
642642
"function" ===
643643
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ exports.useSyncExternalStore = function (
629629
exports.useTransition = function () {
630630
return ReactCurrentDispatcher.current.useTransition();
631631
};
632-
exports.version = "18.3.0-www-modern-120f741e";
632+
exports.version = "18.3.0-www-modern-dc34ad0a";
633633
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
634634
"function" ===
635635
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 16 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (__DEV__) {
6666
return self;
6767
}
6868

69-
var ReactVersion = "18.3.0-www-classic-c7591c48";
69+
var ReactVersion = "18.3.0-www-classic-dbf75d4c";
7070

7171
var LegacyRoot = 0;
7272
var ConcurrentRoot = 1;
@@ -163,9 +163,7 @@ if (__DEV__) {
163163
// Re-export dynamic flags from the www version.
164164
var dynamicFeatureFlags = require("ReactFeatureFlags");
165165

166-
var replayFailedUnitOfWorkWithInvokeGuardedCallback =
167-
dynamicFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback,
168-
enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
166+
var enableDebugTracing = dynamicFeatureFlags.enableDebugTracing,
169167
enableUseRefAccessWarning = dynamicFeatureFlags.enableUseRefAccessWarning,
170168
enableLazyContextPropagation =
171169
dynamicFeatureFlags.enableLazyContextPropagation,
@@ -3728,16 +3726,8 @@ if (__DEV__) {
37283726
}
37293727

37303728
var isHydrating = false; // This flag allows for warning supression when we expect there to be mismatches
3731-
// due to earlier mismatches or a suspended fiber.
3732-
3733-
var didSuspendOrErrorDEV = false; // Hydration errors that were thrown inside this boundary
37343729

37353730
var hydrationErrors = null;
3736-
function didSuspendOrErrorWhileHydratingDEV() {
3737-
{
3738-
return didSuspendOrErrorDEV;
3739-
}
3740-
}
37413731

37423732
function prepareToHydrateHostInstance(fiber, hostContext) {
37433733
{
@@ -13842,25 +13832,8 @@ if (__DEV__) {
1384213832
if (true) {
1384313833
var source = errorInfo.source;
1384413834
var stack = errorInfo.stack;
13845-
var componentStack = stack !== null ? stack : ""; // Browsers support silencing uncaught errors by calling
13846-
// `preventDefault()` in window `error` handler.
13847-
// We record this information as an expando on the error.
13848-
13849-
if (error != null && error._suppressLogging) {
13850-
if (boundary.tag === ClassComponent) {
13851-
// The error is recoverable and was silenced.
13852-
// Ignore it and don't print the stack addendum.
13853-
// This is handy for testing error boundaries without noise.
13854-
return;
13855-
} // The error is fatal. Since the silencing might have
13856-
// been accidental, we'll surface it anyway.
13857-
// However, the browser would have silenced the original error
13858-
// so we'll print it first, and then print the stack addendum.
13859-
13860-
console["error"](error); // Don't transform to our wrapper
13861-
// For a more detailed description of this block, see:
13862-
// https://github.com/facebook/react/pull/13384
13863-
}
13835+
var componentStack = stack !== null ? stack : ""; // TODO: There's no longer a way to silence these warnings e.g. for tests.
13836+
// See https://github.com/facebook/react/pull/13384
1386413837

1386513838
var componentName = source ? getComponentNameFromFiber(source) : null;
1386613839
var componentNameMessage = componentName
@@ -13882,19 +13855,17 @@ if (__DEV__) {
1388213855
("using the error boundary you provided, " +
1388313856
errorBoundaryName +
1388413857
".");
13885-
}
13886-
13887-
var combinedMessage =
13888-
componentNameMessage +
13889-
"\n" +
13890-
componentStack +
13891-
"\n\n" +
13892-
("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
13893-
// We don't include the original error message and JS stack because the browser
13894-
// has already printed it. Even if the application swallows the error, it is still
13895-
// displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
13896-
13897-
console["error"](combinedMessage); // Don't transform to our wrapper
13858+
} // In development, we provide our own message which includes the component stack
13859+
// in addition to the error.
13860+
13861+
console["error"](
13862+
// Don't transform to our wrapper
13863+
"%o\n\n%s\n%s\n\n%s",
13864+
error,
13865+
componentNameMessage,
13866+
componentStack,
13867+
errorBoundaryMessage
13868+
);
1389813869
}
1389913870
} catch (e) {
1390013871
// This method must not throw, or React internal state will get messed up.
@@ -17942,7 +17913,7 @@ if (__DEV__) {
1794217913
return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
1794317914
}
1794417915

17945-
function beginWork$1(current, workInProgress, renderLanes) {
17916+
function beginWork(current, workInProgress, renderLanes) {
1794617917
{
1794717918
if (workInProgress._debugNeedsRemount && current !== null) {
1794817919
// This will restart the begin phase with a new fiber.
@@ -20738,64 +20709,6 @@ if (__DEV__) {
2073820709
}
2073920710
}
2074020711

20741-
// Provided by www
20742-
var ReactFbErrorUtils = require("ReactFbErrorUtils");
20743-
20744-
if (typeof ReactFbErrorUtils.invokeGuardedCallback !== "function") {
20745-
throw new Error(
20746-
"Expected ReactFbErrorUtils.invokeGuardedCallback to be a function."
20747-
);
20748-
}
20749-
20750-
function invokeGuardedCallbackImpl(name, func, context, a, b, c, d, e, f) {
20751-
// This will call `this.onError(err)` if an error was caught.
20752-
ReactFbErrorUtils.invokeGuardedCallback.apply(this, arguments);
20753-
}
20754-
20755-
var hasError = false;
20756-
var caughtError = null; // Used by event system to capture/rethrow the first error.
20757-
var reporter = {
20758-
onError: function (error) {
20759-
hasError = true;
20760-
caughtError = error;
20761-
}
20762-
};
20763-
/**
20764-
* Call a function while guarding against errors that happens within it.
20765-
* Returns an error if it throws, otherwise null.
20766-
*
20767-
* In production, this is implemented using a try-catch. The reason we don't
20768-
* use a try-catch directly is so that we can swap out a different
20769-
* implementation in DEV mode.
20770-
*
20771-
* @param {String} name of the guard to use for logging or debugging
20772-
* @param {Function} func The function to invoke
20773-
* @param {*} context The context to use when calling the function
20774-
* @param {...*} args Arguments for function
20775-
*/
20776-
20777-
function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
20778-
hasError = false;
20779-
caughtError = null;
20780-
invokeGuardedCallbackImpl.apply(reporter, arguments);
20781-
}
20782-
function hasCaughtError() {
20783-
return hasError;
20784-
}
20785-
function clearCaughtError() {
20786-
if (hasError) {
20787-
var error = caughtError;
20788-
hasError = false;
20789-
caughtError = null;
20790-
return error;
20791-
} else {
20792-
throw new Error(
20793-
"clearCaughtError was called but no error was captured. This error " +
20794-
"is likely caused by a bug in React. Please file an issue."
20795-
);
20796-
}
20797-
}
20798-
2079920712
var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
2080020713

2080120714
{
@@ -20818,20 +20731,6 @@ if (__DEV__) {
2081820731
);
2081920732
}
2082020733

20821-
function reportUncaughtErrorInDEV(error) {
20822-
// Wrapping each small part of the commit phase into a guarded
20823-
// callback is a bit too slow (https://github.com/facebook/react/pull/21666).
20824-
// But we rely on it to surface errors to DEV tools like overlays
20825-
// (https://github.com/facebook/react/issues/21712).
20826-
// As a compromise, rethrow only caught errors in a guard.
20827-
{
20828-
invokeGuardedCallback(null, function () {
20829-
throw error;
20830-
});
20831-
clearCaughtError();
20832-
}
20833-
}
20834-
2083520734
function callComponentWillUnmountWithTimer(current, instance) {
2083620735
instance.props = current.memoizedProps;
2083720736
instance.state = current.memoizedState;
@@ -27947,7 +27846,6 @@ if (__DEV__) {
2794727846
error$1
2794827847
) {
2794927848
{
27950-
reportUncaughtErrorInDEV(error$1);
2795127849
setIsRunningInsertionEffect(false);
2795227850
}
2795327851

@@ -28451,83 +28349,6 @@ if (__DEV__) {
2845128349
}
2845228350
}
2845328351
}
28454-
var beginWork;
28455-
28456-
if (replayFailedUnitOfWorkWithInvokeGuardedCallback) {
28457-
var dummyFiber = null;
28458-
28459-
beginWork = function (current, unitOfWork, lanes) {
28460-
// If a component throws an error, we replay it again in a synchronously
28461-
// dispatched event, so that the debugger will treat it as an uncaught
28462-
// error See ReactErrorUtils for more information.
28463-
// Before entering the begin phase, copy the work-in-progress onto a dummy
28464-
// fiber. If beginWork throws, we'll use this to reset the state.
28465-
var originalWorkInProgressCopy = assignFiberPropertiesInDEV(
28466-
dummyFiber,
28467-
unitOfWork
28468-
);
28469-
28470-
try {
28471-
return beginWork$1(current, unitOfWork, lanes);
28472-
} catch (originalError) {
28473-
if (
28474-
didSuspendOrErrorWhileHydratingDEV() ||
28475-
originalError === SuspenseException ||
28476-
originalError === SelectiveHydrationException ||
28477-
(originalError !== null &&
28478-
typeof originalError === "object" &&
28479-
typeof originalError.then === "function")
28480-
) {
28481-
// Don't replay promises.
28482-
// Don't replay errors if we are hydrating and have already suspended or handled an error
28483-
throw originalError;
28484-
} // Don't reset current debug fiber, since we're about to work on the
28485-
// same fiber again.
28486-
// Unwind the failed stack frame
28487-
28488-
resetSuspendedWorkLoopOnUnwind(unitOfWork);
28489-
unwindInterruptedWork(current, unitOfWork); // Restore the original properties of the fiber.
28490-
28491-
assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
28492-
28493-
if (unitOfWork.mode & ProfileMode) {
28494-
// Reset the profiler timer.
28495-
startProfilerTimer(unitOfWork);
28496-
} // Run beginWork again.
28497-
28498-
invokeGuardedCallback(
28499-
null,
28500-
beginWork$1,
28501-
null,
28502-
current,
28503-
unitOfWork,
28504-
lanes
28505-
);
28506-
28507-
if (hasCaughtError()) {
28508-
var replayError = clearCaughtError();
28509-
28510-
if (
28511-
typeof replayError === "object" &&
28512-
replayError !== null &&
28513-
replayError._suppressLogging &&
28514-
typeof originalError === "object" &&
28515-
originalError !== null &&
28516-
!originalError._suppressLogging
28517-
) {
28518-
// If suppressed, let the flag carry over to the original error which is the one we'll rethrow.
28519-
originalError._suppressLogging = true;
28520-
}
28521-
} // We always throw the original error in case the second render pass is not idempotent.
28522-
// This can happen if a memoized function or CommonJS module doesn't throw after first invocation.
28523-
28524-
throw originalError;
28525-
}
28526-
};
28527-
} else {
28528-
beginWork = beginWork$1;
28529-
}
28530-
2853128352
var didWarnAboutUpdateInRender = false;
2853228353
var didWarnAboutUpdateInRenderForAnotherComponent;
2853328354

@@ -29850,55 +29671,6 @@ if (__DEV__) {
2985029671
implementation: portal.implementation
2985129672
};
2985229673
return fiber;
29853-
} // Used for stashing WIP properties to replay failed work in DEV.
29854-
29855-
function assignFiberPropertiesInDEV(target, source) {
29856-
if (target === null) {
29857-
// This Fiber's initial properties will always be overwritten.
29858-
// We only use a Fiber to ensure the same hidden class so DEV isn't slow.
29859-
target = createFiber(IndeterminateComponent, null, null, NoMode);
29860-
} // This is intentionally written as a list of all properties.
29861-
// We tried to use Object.assign() instead but this is called in
29862-
// the hottest path, and Object.assign() was too slow:
29863-
// https://github.com/facebook/react/issues/12502
29864-
// This code is DEV-only so size is not a concern.
29865-
29866-
target.tag = source.tag;
29867-
target.key = source.key;
29868-
target.elementType = source.elementType;
29869-
target.type = source.type;
29870-
target.stateNode = source.stateNode;
29871-
target.return = source.return;
29872-
target.child = source.child;
29873-
target.sibling = source.sibling;
29874-
target.index = source.index;
29875-
target.ref = source.ref;
29876-
target.refCleanup = source.refCleanup;
29877-
target.pendingProps = source.pendingProps;
29878-
target.memoizedProps = source.memoizedProps;
29879-
target.updateQueue = source.updateQueue;
29880-
target.memoizedState = source.memoizedState;
29881-
target.dependencies = source.dependencies;
29882-
target.mode = source.mode;
29883-
target.flags = source.flags;
29884-
target.subtreeFlags = source.subtreeFlags;
29885-
target.deletions = source.deletions;
29886-
target.lanes = source.lanes;
29887-
target.childLanes = source.childLanes;
29888-
target.alternate = source.alternate;
29889-
29890-
{
29891-
target.actualDuration = source.actualDuration;
29892-
target.actualStartTime = source.actualStartTime;
29893-
target.selfBaseDuration = source.selfBaseDuration;
29894-
target.treeBaseDuration = source.treeBaseDuration;
29895-
}
29896-
29897-
target._debugInfo = source._debugInfo;
29898-
target._debugOwner = source._debugOwner;
29899-
target._debugNeedsRemount = source._debugNeedsRemount;
29900-
target._debugHookTypes = source._debugHookTypes;
29901-
return target;
2990229674
}
2990329675

2990429676
function FiberRootNode(

0 commit comments

Comments
 (0)