Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log captured errors sooner #10373

Merged
merged 1 commit into from
Aug 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1189,15 +1189,25 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
capturedErrors = new Map();
}

capturedErrors.set(boundary, {
const capturedError = {
componentName,
componentStack,
error,
errorBoundary: errorBoundaryFound ? boundary.stateNode : null,
errorBoundaryFound,
errorBoundaryName,
willRetry,
});
};

capturedErrors.set(boundary, capturedError);

try {
logCapturedError(capturedError);
} catch (e) {
// Prevent cycle if logCapturedError() throws.
// A cycle may still occur if logCapturedError renders a component that throws.
console.error(e);
}

// If we're in the commit phase, defer scheduling an update on the
// boundary until after the commit is complete
Expand Down Expand Up @@ -1261,15 +1271,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
'bug in React. Please file an issue.',
);

const error = capturedError.error;
try {
logCapturedError(capturedError);
} catch (e) {
// Prevent cycle if logCapturedError() throws.
// A cycle may still occur if logCapturedError renders a component that throws.
console.error(e);
}

switch (effectfulFiber.tag) {
case ClassComponent:
const instance = effectfulFiber.stateNode;
Expand All @@ -1280,14 +1281,14 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(

// Allow the boundary to handle the error, usually by scheduling
// an update to itself
instance.componentDidCatch(error, info);
instance.componentDidCatch(capturedError.error, info);
return;
case HostRoot:
if (firstUncaughtError === null) {
// If this is the host container, we treat it as a no-op error
// boundary. We'll throw the first uncaught error once it's safe to
// do so, at the end of the batch.
firstUncaughtError = error;
firstUncaughtError = capturedError.error;
}
return;
default:
Expand Down