Home / File/ ReactDOMResourceValidation.js — react Source File

ReactDOMResourceValidation.js — react Source File

Architecture documentation for ReactDOMResourceValidation.js, a javascript file in the react codebase. 0 imports, 2 dependents.

File javascript BabelCompiler Validation 2 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  67f50fa6_411e_5d62_45b5_7c7e5640bc66["ReactDOMResourceValidation.js"]
  9c694103_7f39_88d0_6b4d_f9b2ffed5731["ReactFiberConfigDOM.js"]
  9c694103_7f39_88d0_6b4d_f9b2ffed5731 --> 67f50fa6_411e_5d62_45b5_7c7e5640bc66
  4ae326e8_2c2e_2843_d5a5_16edbddd103a["ReactFizzConfigDOM.js"]
  4ae326e8_2c2e_2843_d5a5_16edbddd103a --> 67f50fa6_411e_5d62_45b5_7c7e5640bc66
  style 67f50fa6_411e_5d62_45b5_7c7e5640bc66 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

export function validateLinkPropsForStyleResource(props: any): boolean {
  if (__DEV__) {
    // This should only be called when we know we are opting into Resource semantics (i.e. precedence is not null)
    const {href, onLoad, onError, disabled} = props;
    const includedProps = [];
    if (onLoad) includedProps.push('`onLoad`');
    if (onError) includedProps.push('`onError`');
    if (disabled != null) includedProps.push('`disabled`');

    let includedPropsPhrase = propNamesListJoin(includedProps, 'and');
    includedPropsPhrase += includedProps.length === 1 ? ' prop' : ' props';
    const withArticlePhrase =
      includedProps.length === 1
        ? 'an ' + includedPropsPhrase
        : 'the ' + includedPropsPhrase;

    if (includedProps.length) {
      console.error(
        'React encountered a <link rel="stylesheet" href="%s" ... /> with a `precedence` prop that' +
          ' also included %s. The presence of loading and error handlers indicates an intent to manage' +
          ' the stylesheet loading state from your from your Component code and React will not hoist or' +
          ' deduplicate this stylesheet. If your intent was to have React hoist and deduplciate this stylesheet' +
          ' using the `precedence` prop remove the %s, otherwise remove the `precedence` prop.',
        href,
        withArticlePhrase,
        includedPropsPhrase,
      );
      return true;
    }
  }
  return false;
}

function propNamesListJoin(
  list: Array<string>,
  combinator: 'and' | 'or',
): string {
  switch (list.length) {
    case 0:
      return '';
    case 1:
      return list[0];
    case 2:
      return list[0] + ' ' + combinator + ' ' + list[1];
    default:
      return (
        list.slice(0, -1).join(', ') +
        ', ' +
        combinator +
        ' ' +
        list[list.length - 1]
      );
  }
}

export function getValueDescriptorExpectingObjectForWarning(
  thing: any,
): string {
  return thing === null
    ? '`null`'
    : thing === undefined
      ? '`undefined`'
      : thing === ''
        ? 'an empty string'
        : `something with type "${typeof thing}"`;
}

export function getValueDescriptorExpectingEnumForWarning(thing: any): string {
  return thing === null
    ? '`null`'
    : thing === undefined
      ? '`undefined`'
      : thing === ''
        ? 'an empty string'
        : typeof thing === 'string'
          ? JSON.stringify(thing)
          : `something with type "${typeof thing}"`;
}

Domain

Subdomains

Frequently Asked Questions

What does ReactDOMResourceValidation.js do?
ReactDOMResourceValidation.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in ReactDOMResourceValidation.js?
ReactDOMResourceValidation.js defines 4 function(s): getValueDescriptorExpectingEnumForWarning, getValueDescriptorExpectingObjectForWarning, propNamesListJoin, validateLinkPropsForStyleResource.
What files import ReactDOMResourceValidation.js?
ReactDOMResourceValidation.js is imported by 2 file(s): ReactFiberConfigDOM.js, ReactFizzConfigDOM.js.
Where is ReactDOMResourceValidation.js in the architecture?
ReactDOMResourceValidation.js is located at packages/react-dom-bindings/src/shared/ReactDOMResourceValidation.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-dom-bindings/src/shared).

Analyze Your Own Codebase

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

Try Supermodel Free