Home / Function/ initializeClassErrorUpdate() — react Function Reference

initializeClassErrorUpdate() — react Function Reference

Architecture documentation for the initializeClassErrorUpdate() function in ReactFiberThrow.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  e7ca53d8_6696_2eb1_6326_4df1eb1236b0["initializeClassErrorUpdate()"]
  2945bdb1_d075_d792_a028_13eee518c9d4["ReactFiberThrow.js"]
  e7ca53d8_6696_2eb1_6326_4df1eb1236b0 -->|defined in| 2945bdb1_d075_d792_a028_13eee518c9d4
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b["updateClassComponent()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| e7ca53d8_6696_2eb1_6326_4df1eb1236b0
  f933a08e_fb14_205d_b7b1_ce3073b61e36["throwException()"]
  f933a08e_fb14_205d_b7b1_ce3073b61e36 -->|calls| e7ca53d8_6696_2eb1_6326_4df1eb1236b0
  e2efe0bf_683d_f203_6103_b4f15f21f88a["markFailedErrorBoundaryForHotReloading()"]
  e7ca53d8_6696_2eb1_6326_4df1eb1236b0 -->|calls| e2efe0bf_683d_f203_6103_b4f15f21f88a
  style e7ca53d8_6696_2eb1_6326_4df1eb1236b0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberThrow.js lines 120–201

function initializeClassErrorUpdate(
  update: Update<mixed>,
  root: FiberRoot,
  fiber: Fiber,
  errorInfo: CapturedValue<mixed>,
): void {
  const getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  if (typeof getDerivedStateFromError === 'function') {
    const error = errorInfo.value;
    update.payload = () => {
      return getDerivedStateFromError(error);
    };
    update.callback = () => {
      if (__DEV__) {
        markFailedErrorBoundaryForHotReloading(fiber);
      }
      if (__DEV__) {
        runWithFiberInDEV(
          errorInfo.source,
          logCaughtError,
          root,
          fiber,
          errorInfo,
        );
      } else {
        logCaughtError(root, fiber, errorInfo);
      }
    };
  }

  const inst = fiber.stateNode;
  if (inst !== null && typeof inst.componentDidCatch === 'function') {
    // $FlowFixMe[missing-this-annot]
    update.callback = function callback() {
      if (__DEV__) {
        markFailedErrorBoundaryForHotReloading(fiber);
      }
      if (__DEV__) {
        runWithFiberInDEV(
          errorInfo.source,
          logCaughtError,
          root,
          fiber,
          errorInfo,
        );
      } else {
        logCaughtError(root, fiber, errorInfo);
      }
      if (typeof getDerivedStateFromError !== 'function') {
        // To preserve the preexisting retry behavior of error boundaries,
        // we keep track of which ones already failed during this batch.
        // This gets reset before we yield back to the browser.
        // TODO: Warn in strict mode if getDerivedStateFromError is
        // not defined.
        markLegacyErrorBoundaryAsFailed(this);
      }
      if (__DEV__) {
        callComponentDidCatchInDEV(this, errorInfo);
      } else {
        const error = errorInfo.value;
        const stack = errorInfo.stack;
        this.componentDidCatch(error, {
          componentStack: stack !== null ? stack : '',
        });
      }
      if (__DEV__) {
        if (typeof getDerivedStateFromError !== 'function') {
          // If componentDidCatch is the only error boundary method defined,
          // then it needs to call setState to recover from errors.
          // If no state update is scheduled then the boundary will swallow the error.
          if (!includesSomeLane(fiber.lanes, (SyncLane: Lane))) {
            console.error(
              '%s: Error boundaries should implement getDerivedStateFromError(). ' +
                'In that method, return a state update to display an error message or fallback UI.',
              getComponentNameFromFiber(fiber) || 'Unknown',
            );
          }
        }
      }
    };
  }

Domain

Subdomains

Frequently Asked Questions

What does initializeClassErrorUpdate() do?
initializeClassErrorUpdate() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberThrow.js.
Where is initializeClassErrorUpdate() defined?
initializeClassErrorUpdate() is defined in packages/react-reconciler/src/ReactFiberThrow.js at line 120.
What does initializeClassErrorUpdate() call?
initializeClassErrorUpdate() calls 1 function(s): markFailedErrorBoundaryForHotReloading.
What calls initializeClassErrorUpdate()?
initializeClassErrorUpdate() is called by 2 function(s): throwException, updateClassComponent.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free