MCPcopy Create free account
hub / github.com/reactjs/react-rails / createClassErrorUpdate

Function createClassErrorUpdate

lib/assets/react-source/development/react.js:24409–24466  ·  view source on GitHub ↗
(fiber, errorInfo, expirationTime)

Source from the content-addressed store, hash-verified

24407 }
24408
24409 function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
24410 var update = createUpdate(expirationTime, null);
24411 update.tag = CaptureUpdate;
24412 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
24413
24414 if (typeof getDerivedStateFromError === 'function') {
24415 var error$1 = errorInfo.value;
24416
24417 update.payload = function () {
24418 logError(fiber, errorInfo);
24419 return getDerivedStateFromError(error$1);
24420 };
24421 }
24422
24423 var inst = fiber.stateNode;
24424
24425 if (inst !== null && typeof inst.componentDidCatch === 'function') {
24426 update.callback = function callback() {
24427 {
24428 markFailedErrorBoundaryForHotReloading(fiber);
24429 }
24430
24431 if (typeof getDerivedStateFromError !== 'function') {
24432 // To preserve the preexisting retry behavior of error boundaries,
24433 // we keep track of which ones already failed during this batch.
24434 // This gets reset before we yield back to the browser.
24435 // TODO: Warn in strict mode if getDerivedStateFromError is
24436 // not defined.
24437 markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
24438
24439 logError(fiber, errorInfo);
24440 }
24441
24442 var error$1 = errorInfo.value;
24443 var stack = errorInfo.stack;
24444 this.componentDidCatch(error$1, {
24445 componentStack: stack !== null ? stack : ''
24446 });
24447
24448 {
24449 if (typeof getDerivedStateFromError !== 'function') {
24450 // If componentDidCatch is the only error boundary method defined,
24451 // then it needs to call setState to recover from errors.
24452 // If no state update is scheduled then the boundary will swallow the error.
24453 if (fiber.expirationTime !== Sync) {
24454 error('%s: Error boundaries should implement getDerivedStateFromError(). ' + 'In that method, return a state update to display an error message or fallback UI.', getComponentName(fiber.type) || 'Unknown');
24455 }
24456 }
24457 }
24458 };
24459 } else {
24460 update.callback = function () {
24461 markFailedErrorBoundaryForHotReloading(fiber);
24462 };
24463 }
24464
24465 return update;
24466 }

Callers 2

throwExceptionFunction · 0.85
captureCommitPhaseErrorFunction · 0.85

Calls 6

createUpdateFunction · 0.85
logErrorFunction · 0.85
errorFunction · 0.70
getComponentNameFunction · 0.70

Tested by

no test coverage detected