Home / Function/ $structuralCheck() — react Function Reference

$structuralCheck() — react Function Reference

Architecture documentation for the $structuralCheck() function in index.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  2dc4f0f2_2b7a_cbfd_2005_f338b624f8d1["$structuralCheck()"]
  e7e94027_87c5_661b_dd97_be583c709eb3["index.ts"]
  2dc4f0f2_2b7a_cbfd_2005_f338b624f8d1 -->|defined in| e7e94027_87c5_661b_dd97_be583c709eb3
  style 2dc4f0f2_2b7a_cbfd_2005_f338b624f8d1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/react-compiler-runtime/src/index.ts lines 252–417

export function $structuralCheck(
  oldValue: any,
  newValue: any,
  variableName: string,
  fnName: string,
  kind: string,
  loc: string,
): void {
  function error(l: string, r: string, path: string, depth: number) {
    const str = `${fnName}:${loc} [${kind}] ${variableName}${path} changed from ${l} to ${r} at depth ${depth}`;
    if (seenErrors.has(str)) {
      return;
    }
    seenErrors.add(str);
    console.error(str);
  }
  const depthLimit = 2;
  function recur(oldValue: any, newValue: any, path: string, depth: number) {
    if (depth > depthLimit) {
      return;
    } else if (oldValue === newValue) {
      return;
    } else if (typeof oldValue !== typeof newValue) {
      error(`type ${typeof oldValue}`, `type ${typeof newValue}`, path, depth);
    } else if (typeof oldValue === 'object') {
      const oldArray = Array.isArray(oldValue);
      const newArray = Array.isArray(newValue);
      if (oldValue === null && newValue !== null) {
        error('null', `type ${typeof newValue}`, path, depth);
      } else if (newValue === null) {
        error(`type ${typeof oldValue}`, 'null', path, depth);
      } else if (oldValue instanceof Map) {
        if (!(newValue instanceof Map)) {
          error(`Map instance`, `other value`, path, depth);
        } else if (oldValue.size !== newValue.size) {
          error(
            `Map instance with size ${oldValue.size}`,
            `Map instance with size ${newValue.size}`,
            path,
            depth,
          );
        } else {
          for (const [k, v] of oldValue) {
            if (!newValue.has(k)) {
              error(
                `Map instance with key ${k}`,
                `Map instance without key ${k}`,
                path,
                depth,
              );
            } else {
              recur(v, newValue.get(k), `${path}.get(${k})`, depth + 1);
            }
          }
        }
      } else if (newValue instanceof Map) {
        error('other value', `Map instance`, path, depth);
      } else if (oldValue instanceof Set) {
        if (!(newValue instanceof Set)) {
          error(`Set instance`, `other value`, path, depth);
        } else if (oldValue.size !== newValue.size) {
          error(
            `Set instance with size ${oldValue.size}`,
            `Set instance with size ${newValue.size}`,
            path,
            depth,
          );
        } else {
          for (const v of newValue) {
            if (!oldValue.has(v)) {
              error(
                `Set instance without element ${v}`,
                `Set instance with element ${v}`,
                path,
                depth,
              );
            }
          }
        }
      } else if (newValue instanceof Set) {
        error('other value', `Set instance`, path, depth);

Domain

Subdomains

Frequently Asked Questions

What does $structuralCheck() do?
$structuralCheck() is a function in the react codebase, defined in compiler/packages/react-compiler-runtime/src/index.ts.
Where is $structuralCheck() defined?
$structuralCheck() is defined in compiler/packages/react-compiler-runtime/src/index.ts at line 252.

Analyze Your Own Codebase

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

Try Supermodel Free