Home / Type/ ManualMemoBlockState Type — react Architecture

ManualMemoBlockState Type — react Architecture

Architecture documentation for the ManualMemoBlockState type/interface in ValidatePreservedManualMemoization.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  0dcaab63_44c8_3edf_4a04_32c6062aceee["ManualMemoBlockState"]
  24b95621_3482_c406_4b63_5b9d9e94b5af["ValidatePreservedManualMemoization.ts"]
  0dcaab63_44c8_3edf_4a04_32c6062aceee -->|defined in| 24b95621_3482_c406_4b63_5b9d9e94b5af
  style 0dcaab63_44c8_3edf_4a04_32c6062aceee fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts lines 63–113

type ManualMemoBlockState = {
  /**
   * Tracks reassigned temporaries.
   * This is necessary because useMemo calls are usually inlined.
   * Inlining produces a `let` declaration, followed by reassignments
   * to the newly declared variable (one per return statement).
   * Since InferReactiveScopes does not merge scopes across reassigned
   * variables (except in the case of a mutate-after-phi), we need to
   * track reassignments to validate we're retaining manual memo.
   */
  reassignments: Map<DeclarationId, Set<Identifier>>;
  // The source of the original memoization, used when reporting errors
  loc: SourceLocation;

  /**
   * Values produced within manual memoization blocks.
   * We track these to ensure our inferred dependencies are
   * produced before the manual memo block starts
   *
   * As an example:
   * ```js
   * // source
   * const result = useMemo(() => {
   *   return [makeObject(input1), input2],
   * }, [input1, input2]);
   * ```
   * Here, we record inferred dependencies as [input1, input2]
   * but not t0
   * ```js
   * // StartMemoize
   * let t0;
   * if ($[0] != input1) {
   *   t0 = makeObject(input1);
   *   // ...
   * } else { ... }
   *
   * let result;
   * if ($[1] != t0 || $[2] != input2) {
   *   result = [t0, input2];
   * } else { ... }
   * ```
   */
  decls: Set<DeclarationId>;

  /*
   * normalized depslist from useMemo/useCallback
   * callsite in source
   */
  depsFromSource: Array<ManualMemoDependency> | null;
  manualMemoId: number;
};

Frequently Asked Questions

What is the ManualMemoBlockState type?
ManualMemoBlockState is a type/interface in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts.
Where is ManualMemoBlockState defined?
ManualMemoBlockState is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts at line 63.

Analyze Your Own Codebase

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

Try Supermodel Free