MCPcopy Index your code
hub / github.com/react/react / captureCommitPhaseError

Function captureCommitPhaseError

packages/react-reconciler/src/ReactFiberWorkLoop.js:4674–4729  ·  view source on GitHub ↗
(
  sourceFiber: Fiber,
  nearestMountedAncestor: Fiber | null,
  error: mixed,
)

Source from the content-addressed store, hash-verified

4672}
4673
4674export function captureCommitPhaseError(
4675 sourceFiber: Fiber,
4676 nearestMountedAncestor: Fiber | null,
4677 error: mixed,
4678) {
4679 if (__DEV__) {
4680 setIsRunningInsertionEffect(false);
4681 }
4682 if (sourceFiber.tag === HostRoot) {
4683 // Error was thrown at the root. There is no parent, so the root
4684 // itself should capture it.
4685 captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
4686 return;
4687 }
4688
4689 let fiber = nearestMountedAncestor;
4690 while (fiber !== null) {
4691 if (fiber.tag === HostRoot) {
4692 captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
4693 return;
4694 } else if (fiber.tag === ClassComponent) {
4695 const ctor = fiber.type;
4696 const instance = fiber.stateNode;
4697 if (
4698 typeof ctor.getDerivedStateFromError === 'function' ||
4699 (typeof instance.componentDidCatch === 'function' &&
4700 !isAlreadyFailedLegacyErrorBoundary(instance))
4701 ) {
4702 const errorInfo = createCapturedValueAtFiber(error, sourceFiber);
4703 if (enableProfilerTimer && enableComponentPerformanceTrack) {
4704 recordEffectError(errorInfo);
4705 }
4706 const update = createClassErrorUpdate((SyncLane: Lane));
4707 const root = enqueueUpdate(fiber, update, (SyncLane: Lane));
4708 if (root !== null) {
4709 initializeClassErrorUpdate(update, root, fiber, errorInfo);
4710 markRootUpdated(root, SyncLane);
4711 ensureRootIsScheduled(root);
4712 }
4713 return;
4714 }
4715 }
4716 fiber = fiber.return;
4717 }
4718
4719 if (__DEV__) {
4720 console.error(
4721 'Internal React error: Attempted to capture a commit phase error ' +
4722 'inside a detached tree. This indicates a bug in React. Potential ' +
4723 'causes include deleting the same fiber more than once, committing an ' +
4724 'already-finished tree, or an inconsistent return pointer.\n\n' +
4725 'Error message:\n\n%s',
4726 error,
4727 );
4728 }
4729}
4730
4731export function attachPingListener(

Callers 15

commitClassDidMountFunction · 0.90
commitClassCallbacksFunction · 0.90
commitRootCallbacksFunction · 0.90
commitClassSnapshotFunction · 0.90

Calls 11

recordEffectErrorFunction · 0.90
createClassErrorUpdateFunction · 0.90
enqueueUpdateFunction · 0.90
markRootUpdatedFunction · 0.90
ensureRootIsScheduledFunction · 0.90
errorMethod · 0.65

Tested by

no test coverage detected