Home / Function/ describeNativeComponentFrame() — react Function Reference

describeNativeComponentFrame() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  5233c9e5_06be_c1c7_1ac7_e793934cd625["describeNativeComponentFrame()"]
  c59dc57c_ed0c_b6cd_803d_b7eeab46f99e["DevToolsComponentStackFrame.js"]
  5233c9e5_06be_c1c7_1ac7_e793934cd625 -->|defined in| c59dc57c_ed0c_b6cd_803d_b7eeab46f99e
  5cbc52da_c9f7_de68_6aad_129d03cab0de["describeClassComponentFrame()"]
  5cbc52da_c9f7_de68_6aad_129d03cab0de -->|calls| 5233c9e5_06be_c1c7_1ac7_e793934cd625
  b4c6f9e5_d92e_ecc4_3cd0_0b109bf71a32["describeFunctionComponentFrame()"]
  b4c6f9e5_d92e_ecc4_3cd0_0b109bf71a32 -->|calls| 5233c9e5_06be_c1c7_1ac7_e793934cd625
  6ad9f549_2ad9_74e1_a410_dcaefa5b42d6["disableLogs()"]
  5233c9e5_06be_c1c7_1ac7_e793934cd625 -->|calls| 6ad9f549_2ad9_74e1_a410_dcaefa5b42d6
  style 5233c9e5_06be_c1c7_1ac7_e793934cd625 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-devtools-shared/src/backend/shared/DevToolsComponentStackFrame.js lines 54–135

export function describeNativeComponentFrame(
  fn: Function,
  construct: boolean,
  currentDispatcherRef: CurrentDispatcherRef,
): 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;
    }
  }

  const previousPrepareStackTrace = Error.prepareStackTrace;
  // $FlowFixMe[incompatible-type] It does accept undefined.
  Error.prepareStackTrace = undefined;

  reentry = true;

  // Override the dispatcher so effects scheduled by this shallow render are thrown away.
  //
  // Note that unlike the code this was forked from (in ReactComponentStackFrame)
  // DevTools should override the dispatcher even when DevTools is compiled in production mode,
  // because the app itself may be in development mode and log errors/warnings.
  const previousDispatcher = currentDispatcherRef.H;
  currentDispatcherRef.H = null;
  disableLogs();
  try {
    // NOTE: keep in sync with the implementation in ReactComponentStackFrame

    /**
     * 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);
            }

Domain

Subdomains

Frequently Asked Questions

What does describeNativeComponentFrame() do?
describeNativeComponentFrame() is a function in the react codebase, defined in packages/react-devtools-shared/src/backend/shared/DevToolsComponentStackFrame.js.
Where is describeNativeComponentFrame() defined?
describeNativeComponentFrame() is defined in packages/react-devtools-shared/src/backend/shared/DevToolsComponentStackFrame.js at line 54.
What does describeNativeComponentFrame() call?
describeNativeComponentFrame() calls 1 function(s): disableLogs.
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