Home / Function/ preload() — react Function Reference

preload() — react Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

packages/react-dom/src/shared/ReactDOMFloat.js lines 89–151

export function preload(href: string, options: PreloadOptions) {
  if (__DEV__) {
    let encountered = '';
    if (typeof href !== 'string' || !href) {
      encountered += ` The \`href\` argument encountered was ${getValueDescriptorExpectingObjectForWarning(
        href,
      )}.`;
    }
    if (options == null || typeof options !== 'object') {
      encountered += ` The \`options\` argument encountered was ${getValueDescriptorExpectingObjectForWarning(
        options,
      )}.`;
    } else if (typeof options.as !== 'string' || !options.as) {
      encountered += ` The \`as\` option encountered was ${getValueDescriptorExpectingObjectForWarning(
        options.as,
      )}.`;
    }
    if (encountered) {
      console.error(
        'ReactDOM.preload(): Expected two arguments, a non-empty `href` string and an `options` object with an `as` property valid for a `<link rel="preload" as="..." />` tag.%s',
        encountered,
      );
    }
  }
  if (
    typeof href === 'string' &&
    // We check existence because we cannot enforce this function is actually called with the stated type
    typeof options === 'object' &&
    options !== null &&
    typeof options.as === 'string'
  ) {
    const as = options.as;
    const crossOrigin = getCrossOriginStringAs(as, options.crossOrigin);
    ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
      .L(/* preload */ href, as, {
        crossOrigin,
        integrity:
          typeof options.integrity === 'string' ? options.integrity : undefined,
        nonce: typeof options.nonce === 'string' ? options.nonce : undefined,
        type: typeof options.type === 'string' ? options.type : undefined,
        fetchPriority:
          typeof options.fetchPriority === 'string'
            ? options.fetchPriority
            : undefined,
        referrerPolicy:
          typeof options.referrerPolicy === 'string'
            ? options.referrerPolicy
            : undefined,
        imageSrcSet:
          typeof options.imageSrcSet === 'string'
            ? options.imageSrcSet
            : undefined,
        imageSizes:
          typeof options.imageSizes === 'string'
            ? options.imageSizes
            : undefined,
        media: typeof options.media === 'string' ? options.media : undefined,
      });
  }
  // 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 preload() do?
preload() is a function in the react codebase, defined in packages/react-dom/src/shared/ReactDOMFloat.js.
Where is preload() defined?
preload() is defined in packages/react-dom/src/shared/ReactDOMFloat.js at line 89.
What does preload() call?
preload() 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