( sourceFiber: Fiber, nearestMountedAncestor: Fiber | null, error: mixed, )
| 4672 | } |
| 4673 | |
| 4674 | export 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 | |
| 4731 | export function attachPingListener( |
no test coverage detected