Home / File/ repro-invalid-pruned-scope-leaks-value-via-alias.ts — react Source File

repro-invalid-pruned-scope-leaks-value-via-alias.ts — react Source File

Architecture documentation for repro-invalid-pruned-scope-leaks-value-via-alias.ts, a typescript file in the react codebase. 2 imports, 0 dependents.

File typescript TestingUtilities Fixtures 2 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  80854c9c_b8e1_bb65_8af8_68fd6483d24e["repro-invalid-pruned-scope-leaks-value-via-alias.ts"]
  7b0f5d46_efcb_4a2d_89c1_7cee4a0f9bc8["invariant"]
  80854c9c_b8e1_bb65_8af8_68fd6483d24e --> 7b0f5d46_efcb_4a2d_89c1_7cee4a0f9bc8
  006eec3d_77a9_4a47_e6c1_a96d7a6c9c05["shared-runtime"]
  80854c9c_b8e1_bb65_8af8_68fd6483d24e --> 006eec3d_77a9_4a47_e6c1_a96d7a6c9c05
  style 80854c9c_b8e1_bb65_8af8_68fd6483d24e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import invariant from 'invariant';
import {makeObject_Primitives, mutate, sum, useIdentity} from 'shared-runtime';

/**
 * Here, `z`'s original memo block is removed due to the inner hook call.
 * However, we also infer that `z` is non-reactive, so by default we would create
 * the memo block for `thing = [y, z]` as only depending on `y`.
 *
 * This could then mean that `thing[1]` and `z` may not refer to the same value,
 * since z recreates every time but `thing` doesn't correspondingly invalidate.
 *
 * The fix is to consider pruned memo block outputs as reactive, since they will
 * recreate on every render. This means `thing` depends on both y and z.
 */
function MyApp({count}) {
  const z = makeObject_Primitives();
  const x = useIdentity(2);
  const y = sum(x, count);
  mutate(z);
  const z2 = z;
  const thing = [y, z2];
  if (thing[1] !== z) {
    invariant(false, 'oh no!');
  }
  return thing;
}

export const FIXTURE_ENTRYPOINT = {
  fn: MyApp,
  params: [{count: 2}],
  sequentialRenders: [{count: 2}, {count: 2}, {count: 3}],
};

Subdomains

Functions

Dependencies

  • invariant
  • shared-runtime

Frequently Asked Questions

What does repro-invalid-pruned-scope-leaks-value-via-alias.ts do?
repro-invalid-pruned-scope-leaks-value-via-alias.ts is a source file in the react codebase, written in typescript. It belongs to the TestingUtilities domain, Fixtures subdomain.
What functions are defined in repro-invalid-pruned-scope-leaks-value-via-alias.ts?
repro-invalid-pruned-scope-leaks-value-via-alias.ts defines 1 function(s): MyApp.
What does repro-invalid-pruned-scope-leaks-value-via-alias.ts depend on?
repro-invalid-pruned-scope-leaks-value-via-alias.ts imports 2 module(s): invariant, shared-runtime.
Where is repro-invalid-pruned-scope-leaks-value-via-alias.ts in the architecture?
repro-invalid-pruned-scope-leaks-value-via-alias.ts is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-invalid-pruned-scope-leaks-value-via-alias.ts (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