Home / Function/ preloadModule() — react Function Reference

preloadModule() — react Function Reference

Architecture documentation for the preloadModule() function in ReactDOMFloat.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  a5580aac_8777_020f_2182_f5394bec2548["preloadModule()"]
  3ea12e77_bd9c_ec2a_fb3c_db692f520137["ReactDOMFloat.js"]
  a5580aac_8777_020f_2182_f5394bec2548 -->|defined in| 3ea12e77_bd9c_ec2a_fb3c_db692f520137
  24cdce56_f095_bb7e_3cbd_6bc0a497e302["getValueDescriptorExpectingObjectForWarning()"]
  a5580aac_8777_020f_2182_f5394bec2548 -->|calls| 24cdce56_f095_bb7e_3cbd_6bc0a497e302
  style a5580aac_8777_020f_2182_f5394bec2548 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-dom/src/shared/ReactDOMFloat.js lines 153–203

export function preloadModule(href: string, options?: ?PreloadModuleOptions) {
  if (__DEV__) {
    let encountered = '';
    if (typeof href !== 'string' || !href) {
      encountered += ` The \`href\` argument encountered was ${getValueDescriptorExpectingObjectForWarning(
        href,
      )}.`;
    }
    if (options !== undefined && typeof options !== 'object') {
      encountered += ` The \`options\` argument encountered was ${getValueDescriptorExpectingObjectForWarning(
        options,
      )}.`;
    } else if (options && 'as' in options && typeof options.as !== 'string') {
      encountered += ` The \`as\` option encountered was ${getValueDescriptorExpectingObjectForWarning(
        options.as,
      )}.`;
    }
    if (encountered) {
      console.error(
        'ReactDOM.preloadModule(): Expected two arguments, a non-empty `href` string and, optionally, an `options` object with an `as` property valid for a `<link rel="modulepreload" as="..." />` tag.%s',
        encountered,
      );
    }
  }
  if (typeof href === 'string') {
    if (options) {
      const crossOrigin = getCrossOriginStringAs(
        options.as,
        options.crossOrigin,
      );
      ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
        .m(/* preloadModule */ href, {
          as:
            typeof options.as === 'string' && options.as !== 'script'
              ? options.as
              : undefined,
          crossOrigin,
          integrity:
            typeof options.integrity === 'string'
              ? options.integrity
              : undefined,
        });
    } else {
      ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
        .m(/* preloadModule */ href);
    }
  }
  // We don't error because preload needs to be resilient to being called in a variety of scopes
  // and the runtime may not be capable of responding. The function is optimistic and not critical
  // so we favor silent bailout over warning or erroring.
}

Domain

Subdomains

Frequently Asked Questions

What does preloadModule() do?
preloadModule() is a function in the react codebase, defined in packages/react-dom/src/shared/ReactDOMFloat.js.
Where is preloadModule() defined?
preloadModule() is defined in packages/react-dom/src/shared/ReactDOMFloat.js at line 153.
What does preloadModule() call?
preloadModule() calls 1 function(s): getValueDescriptorExpectingObjectForWarning.

Analyze Your Own Codebase

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

Try Supermodel Free