Home / File/ error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx — react Source File

error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx — react Source File

Architecture documentation for error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx, a tsx file in the react codebase. 2 imports, 0 dependents.

File tsx TestingUtilities Fixtures 2 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  aa2cbd6e_1456_3777_574a_0fe679c06ca5["error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx"]
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  aa2cbd6e_1456_3777_574a_0fe679c06ca5 --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  006eec3d_77a9_4a47_e6c1_a96d7a6c9c05["shared-runtime"]
  aa2cbd6e_1456_3777_574a_0fe679c06ca5 --> 006eec3d_77a9_4a47_e6c1_a96d7a6c9c05
  style aa2cbd6e_1456_3777_574a_0fe679c06ca5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
import {useMemo} from 'react';
import {ValidateMemoization, useHook} from 'shared-runtime';

function UnmemoizedCallbackCapturedInContextVariable({cond1, cond2}) {
  // The return value is captured by `x` which is a context variable, which
  // extends a's range to include the call instruction. This prevents the entire
  // range from being memoized
  const a = useHook();
  // Because b is also part of that same mutable range, it can't be memoized either
  const b = useMemo(() => ({}), []);

  // Conditional assignment without a subsequent mutation normally doesn't create a mutable
  // range, but in this case we're reassigning a context variable
  let x;
  if (cond1) {
    x = a;
  } else if (cond2) {
    x = b;
  } else {
    return null;
  }

  const f = () => {
    return x;
  };
  const result = f();

  return <ValidateMemoization inputs={[cond1, cond2]} output={result} />;
}

export const FIXTURE_ENTRYPOINT = {
  fn: UnmemoizedCallbackCapturedInContextVariable,
  params: [{cond1: true, cond2: false}],
  sequentialRenders: [
    {cond1: true, cond2: true},
    {cond1: false, cond2: true},
    {cond1: false, cond2: true}, // fails sprout bc memoization is not preserved
    {cond1: false, cond2: false},
  ],
};

Subdomains

Dependencies

  • react
  • shared-runtime

Frequently Asked Questions

What does error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx do?
error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx is a source file in the react codebase, written in tsx. It belongs to the TestingUtilities domain, Fixtures subdomain.
What functions are defined in error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx?
error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx defines 1 function(s): UnmemoizedCallbackCapturedInContextVariable.
What does error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx depend on?
error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx imports 2 module(s): react, shared-runtime.
Where is error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx in the architecture?
error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx (domain: TestingUtilities, subdomain: Fixtures, directory: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler).

Analyze Your Own Codebase

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

Try Supermodel Free