Home / Function/ describeNativeComponentFrame() — react Function Reference

describeNativeComponentFrame() — react Function Reference

Architecture documentation for the describeNativeComponentFrame() function in ReactComponentStackFrame.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  6d0e3213_ad1e_7452_7bd3_2195b3ee058e["describeNativeComponentFrame()"]
  823a67e4_24d9_f152_2b72_4a49ef93fd70["ReactComponentStackFrame.js"]
  6d0e3213_ad1e_7452_7bd3_2195b3ee058e -->|defined in| 823a67e4_24d9_f152_2b72_4a49ef93fd70
  f3b13411_470a_c6ef_8784_404a2c8fd6f1["describeClassComponentFrame()"]
  f3b13411_470a_c6ef_8784_404a2c8fd6f1 -->|calls| 6d0e3213_ad1e_7452_7bd3_2195b3ee058e
  38229b53_eb43_58d9_c555_f9796c72d964["describeFunctionComponentFrame()"]
  38229b53_eb43_58d9_c555_f9796c72d964 -->|calls| 6d0e3213_ad1e_7452_7bd3_2195b3ee058e
  style 6d0e3213_ad1e_7452_7bd3_2195b3ee058e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shared/ReactComponentStackFrame.js lines 82–158

export function describeNativeComponentFrame(
  fn: Function,
  construct: boolean,
): string {
  // If something asked for a stack inside a fake render, it should get ignored.
  if (!fn || reentry) {
    return '';
  }

  if (__DEV__) {
    const frame = componentFrameCache.get(fn);
    if (frame !== undefined) {
      return frame;
    }
  }

  reentry = true;
  const previousPrepareStackTrace = Error.prepareStackTrace;
  Error.prepareStackTrace = DefaultPrepareStackTrace;
  let previousDispatcher = null;

  if (__DEV__) {
    previousDispatcher = ReactSharedInternals.H;
    // Set the dispatcher in DEV because this might be call in the render function
    // for warnings.
    ReactSharedInternals.H = null;
    disableLogs();
  }
  try {
    /**
     * Finding a common stack frame between sample and control errors can be
     * tricky given the different types and levels of stack trace truncation from
     * different JS VMs. So instead we'll attempt to control what that common
     * frame should be through this object method:
     * Having both the sample and control errors be in the function under the
     * `DescribeNativeComponentFrameRoot` property, + setting the `name` and
     * `displayName` properties of the function ensures that a stack
     * frame exists that has the method name `DescribeNativeComponentFrameRoot` in
     * it for both control and sample stacks.
     */
    const RunInRootFrame = {
      DetermineComponentFrameRoot(): [?string, ?string] {
        let control;
        try {
          // This should throw.
          if (construct) {
            // Something should be setting the props in the constructor.
            const Fake = function () {
              throw Error();
            };
            // $FlowFixMe[prop-missing]
            Object.defineProperty(Fake.prototype, 'props', {
              set: function () {
                // We use a throwing setter instead of frozen or non-writable props
                // because that won't throw in a non-strict mode function.
                throw Error();
              },
            });
            if (typeof Reflect === 'object' && Reflect.construct) {
              // We construct a different control for this case to include any extra
              // frames added by the construct call.
              try {
                Reflect.construct(Fake, []);
              } catch (x) {
                control = x;
              }
              Reflect.construct(fn, [], Fake);
            } else {
              try {
                Fake.call();
              } catch (x) {
                control = x;
              }
              // $FlowFixMe[prop-missing] found when upgrading Flow
              fn.call(Fake.prototype);
            }
          } else {

Domain

Subdomains

Frequently Asked Questions

What does describeNativeComponentFrame() do?
describeNativeComponentFrame() is a function in the react codebase, defined in packages/shared/ReactComponentStackFrame.js.
Where is describeNativeComponentFrame() defined?
describeNativeComponentFrame() is defined in packages/shared/ReactComponentStackFrame.js at line 82.
What calls describeNativeComponentFrame()?
describeNativeComponentFrame() is called by 2 function(s): describeClassComponentFrame, describeFunctionComponentFrame.

Analyze Your Own Codebase

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

Try Supermodel Free