Home / Function/ visitInstruction() — react Function Reference

visitInstruction() — react Function Reference

Architecture documentation for the visitInstruction() function in ValidateMemoizedEffectDependencies.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  b0098168_1428_1a79_dc10_829e8e1a5595["visitInstruction()"]
  5cd10448_f0eb_0786_b718_13989afbbde5["Visitor"]
  b0098168_1428_1a79_dc10_829e8e1a5595 -->|defined in| 5cd10448_f0eb_0786_b718_13989afbbde5
  af4d3127_0abf_3e44_50a8_d7a9dd0b9b58["visitInstruction()"]
  b0098168_1428_1a79_dc10_829e8e1a5595 -->|calls| af4d3127_0abf_3e44_50a8_d7a9dd0b9b58
  ff7b048c_7d03_6dc5_346d_49078c4cb8d3["isEffectHook()"]
  b0098168_1428_1a79_dc10_829e8e1a5595 -->|calls| ff7b048c_7d03_6dc5_346d_49078c4cb8d3
  11746e9a_2fdf_98bb_bb3c_a63d8b200df2["isMutable()"]
  b0098168_1428_1a79_dc10_829e8e1a5595 -->|calls| 11746e9a_2fdf_98bb_bb3c_a63d8b200df2
  325a6f42_549f_1115_a1f6_935e8be237cc["isUnmemoized()"]
  b0098168_1428_1a79_dc10_829e8e1a5595 -->|calls| 325a6f42_549f_1115_a1f6_935e8be237cc
  073c81a5_c389_d108_5b8f_4d6dc6eece83["push()"]
  b0098168_1428_1a79_dc10_829e8e1a5595 -->|calls| 073c81a5_c389_d108_5b8f_4d6dc6eece83
  940018a6_e890_d3b5_6044_cb8053953421["traverseInstruction()"]
  b0098168_1428_1a79_dc10_829e8e1a5595 -->|calls| 940018a6_e890_d3b5_6044_cb8053953421
  style b0098168_1428_1a79_dc10_829e8e1a5595 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateMemoizedEffectDependencies.ts lines 91–121

  override visitInstruction(
    instruction: ReactiveInstruction,
    state: CompilerError,
  ): void {
    this.traverseInstruction(instruction, state);
    if (
      instruction.value.kind === 'CallExpression' &&
      isEffectHook(instruction.value.callee.identifier) &&
      instruction.value.args.length >= 2
    ) {
      const deps = instruction.value.args[1]!;
      if (
        deps.kind === 'Identifier' &&
        /*
         * TODO: isMutable is not safe to call here as it relies on identifier mutableRange which is no longer valid at this point
         * in the pipeline
         */
        (isMutable(instruction as Instruction, deps) ||
          isUnmemoized(deps.identifier, this.scopes))
      ) {
        state.push({
          category: ErrorCategory.EffectDependencies,
          reason:
            'React Compiler has skipped optimizing this component because the effect dependencies could not be memoized. Unmemoized effect dependencies can trigger an infinite loop or other unexpected behavior',
          description: null,
          loc: typeof instruction.loc !== 'symbol' ? instruction.loc : null,
          suggestions: null,
        });
      }
    }
  }

Domain

Subdomains

Frequently Asked Questions

What does visitInstruction() do?
visitInstruction() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateMemoizedEffectDependencies.ts.
Where is visitInstruction() defined?
visitInstruction() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateMemoizedEffectDependencies.ts at line 91.
What does visitInstruction() call?
visitInstruction() calls 6 function(s): isEffectHook, isMutable, isUnmemoized, push, traverseInstruction, visitInstruction.

Analyze Your Own Codebase

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

Try Supermodel Free