Repository: facebook/react
File: packages/react-server/src/ReactFizzServer.js (JavaScript)

Code before:
      for (let i = 0; i < stack.length; i++) {
        const componentInfo: ReactComponentInfo = (stack[i]: any);
        if (typeof componentInfo.name !== 'string') {
          continue;
        }
        let name = componentInfo.name;
        const env = componentInfo.env;
        if (env) {
          name += ' (' + env + ')';
        }
        node = {
          tag: 3,
          parent: node,
          type: name,
          owner: componentInfo.owner,
          stack: componentInfo.stack,
        };
      }
    }
    return node;
  }
  // eslint-disable-next-line react-internal/prod-error-codes
  throw new Error(
    'createServerComponentStack should never be called in production. This is a bug in React.',
  );
}

function createComponentStackFromType(
  task: Task,
  type: Function | string,
  owner: null | ReactComponentInfo | ComponentStackNode, // DEV only
  stack: null | Error, // DEV only
): ComponentStackNode {
  if (typeof type === 'string') {
    return createBuiltInComponentStack(task, type, owner, stack);
  }
  if (shouldConstruct(type)) {
    return createClassComponentStack(task, type, owner, stack);
  }
  return createFunctionComponentStack(task, type, owner, stack);
}

type ThrownInfo = {
  componentStack?: string,
};
export type ErrorInfo = ThrownInfo;
export type PostponeInfo = ThrownInfo;

function getThrownInfo(node: null | ComponentStackNode): ThrownInfo {
  const errorInfo: ThrownInfo = {};
  if (node) {

Review comment (suggestion):
Is the reason here that this error shouldn't appear in prod bundles? We usually call this out explicitly e.g.  https://github.com/facebook/react/blob/d40ea875a42d5726e8a7e5a6f47db2dbe314957d/packages/react-server/src/ReactFlightServer.js#L3269-L3273

Code after:
  if (__DEV__) {
    let node = task.componentStack;
    if (debugInfo != null) {
      const stack: ReactDebugInfo = debugInfo;
      for (let i = 0; i < stack.length; i++) {
        const componentInfo: ReactComponentInfo = (stack[i]: any);
        if (typeof componentInfo.name !== 'string') {
          continue;
        }
        let name = componentInfo.name;
        const env = componentInfo.env;
        if (env) {
          name += ' (' + env + ')';
        }
        node = {
          tag: 3,
          parent: node,
          type: name,
          owner: componentInfo.owner,
          stack: componentInfo.stack,
        };
      }
    }
    return node;
  }
  // eslint-disable-next-line react-internal/prod-error-codes
  throw new Error(
    'createServerComponentStack should never be called in production. This is a bug in React.',
  );
}

function createComponentStackFromType(
  task: Task,
  type: Function | string,
  owner: null | ReactComponentInfo | ComponentStackNode, // DEV only
  stack: null | Error, // DEV only
): ComponentStackNode {
  if (typeof type === 'string') {
    return createBuiltInComponentStack(task, type, owner, stack);
  }
  if (shouldConstruct(type)) {
    return createClassComponentStack(task, type, owner, stack);
  }
  return createFunctionComponentStack(task, type, owner, stack);
}

type ThrownInfo = {
  componentStack?: string,
};
export type ErrorInfo = ThrownInfo;
export type PostponeInfo = ThrownInfo;