Home / Function/ addChunkDebugInfo() — react Function Reference

addChunkDebugInfo() — react Function Reference

Architecture documentation for the addChunkDebugInfo() function in ReactFlightClientConfigBundlerWebpackBrowser.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  8741ec29_009a_77f7_99f7_6d31782f1d2a["addChunkDebugInfo()"]
  f69e300f_c523_bd54_35b8_9ea0250d7ffe["ReactFlightClientConfigBundlerWebpackBrowser.js"]
  8741ec29_009a_77f7_99f7_6d31782f1d2a -->|defined in| f69e300f_c523_bd54_35b8_9ea0250d7ffe
  style 8741ec29_009a_77f7_99f7_6d31782f1d2a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-server-dom-webpack/src/client/ReactFlightClientConfigBundlerWebpackBrowser.js lines 41–129

export function addChunkDebugInfo(
  target: ReactDebugInfo,
  chunkId: string,
  filename: string,
): void {
  if (!__DEV__) {
    return;
  }
  let ioInfo = chunkIOInfoCache.get(chunkId);
  if (ioInfo === undefined) {
    const scriptFilename = __webpack_get_script_filename__(chunkId);
    let href;
    try {
      // $FlowFixMe
      href = new URL(scriptFilename, document.baseURI).href;
    } catch (_) {
      href = scriptFilename;
    }
    let start = -1;
    let end = -1;
    let byteSize = 0;
    // $FlowFixMe[method-unbinding]
    if (typeof performance.getEntriesByType === 'function') {
      // We may be able to collect the start and end time of this resource from Performance Observer.
      const resourceEntries = performance.getEntriesByType('resource');
      for (let i = 0; i < resourceEntries.length; i++) {
        const resourceEntry = resourceEntries[i];
        if (resourceEntry.name === href) {
          start = resourceEntry.startTime;
          end = start + resourceEntry.duration;
          // $FlowFixMe[prop-missing]
          byteSize = (resourceEntry.transferSize: any) || 0;
        }
      }
    }
    const value = Promise.resolve(href);
    // $FlowFixMe
    value.status = 'fulfilled';
    // $FlowFixMe
    value.value = {
      chunkId: chunkId,
      href: href,
      // Is there some more useful representation for the chunk?
    };
    // Create a fake stack frame that points to the beginning of the chunk. This is
    // probably not source mapped so will link to the compiled source rather than
    // any individual file that goes into the chunks.
    const fakeStack = new Error('react-stack-top-frame');
    if (fakeStack.stack.startsWith('Error: react-stack-top-frame')) {
      // Looks like V8
      fakeStack.stack =
        'Error: react-stack-top-frame\n' +
        // Add two frames since we always trim one off the top.
        '    at Client Component Bundle (' +
        href +
        ':1:1)\n' +
        '    at Client Component Bundle (' +
        href +
        ':1:1)';
    } else {
      // Looks like Firefox or Safari.
      // Add two frames since we always trim one off the top.
      fakeStack.stack =
        'Client Component Bundle@' +
        href +
        ':1:1\n' +
        'Client Component Bundle@' +
        href +
        ':1:1';
    }
    ioInfo = ({
      name: 'script',
      start: start,
      end: end,
      value: value,
      debugStack: fakeStack,
    }: ReactIOInfo);
    if (byteSize > 0) {
      // $FlowFixMe[cannot-write]
      ioInfo.byteSize = byteSize;
    }

Domain

Subdomains

Frequently Asked Questions

What does addChunkDebugInfo() do?
addChunkDebugInfo() is a function in the react codebase, defined in packages/react-server-dom-webpack/src/client/ReactFlightClientConfigBundlerWebpackBrowser.js.
Where is addChunkDebugInfo() defined?
addChunkDebugInfo() is defined in packages/react-server-dom-webpack/src/client/ReactFlightClientConfigBundlerWebpackBrowser.js at line 41.

Analyze Your Own Codebase

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

Try Supermodel Free