Home / File/ pruned-nonreactive-obj.js — react Source File

pruned-nonreactive-obj.js — react Source File

Architecture documentation for pruned-nonreactive-obj.js, a javascript file in the react codebase. 2 imports, 0 dependents.

File javascript TestingUtilities Fixtures 2 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  35ecf3bd_a133_2f56_cd45_98fa3edd4b79["pruned-nonreactive-obj.js"]
  006eec3d_77a9_4a47_e6c1_a96d7a6c9c05["shared-runtime"]
  35ecf3bd_a133_2f56_cd45_98fa3edd4b79 --> 006eec3d_77a9_4a47_e6c1_a96d7a6c9c05
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  35ecf3bd_a133_2f56_cd45_98fa3edd4b79 --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  style 35ecf3bd_a133_2f56_cd45_98fa3edd4b79 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// @inferEffectDependencies
import {useIdentity, mutate, makeObject} from 'shared-runtime';
import {useEffect, AUTODEPS} from 'react';

/**
 * When a semantically non-reactive value has a pruned scope (i.e. the object
 * identity becomes reactive, but the underlying value it represents should be
 * constant), the compiler can choose to either
 * - add it as a dependency (and rerun the effect)
 * - not add it as a dependency
 *
 * We keep semantically non-reactive values in both memo block and effect
 * dependency arrays to avoid versioning invariants e.g. `x !== y.aliasedX`.
 * ```js
 * function Component() {
 *   // obj is semantically non-reactive, but its memo scope is pruned due to
 *   // the interleaving hook call
 *   const obj = {};
 *   useHook();
 *   write(obj);
 *
 *   const ref = useRef();
 *
 *   // this effect needs to be rerun when obj's referential identity changes,
 *   // because it might alias obj to a useRef / mutable store.
 *   useEffect(() => ref.current = obj, ???);
 *
 *   // in a custom hook (or child component), the user might expect versioning
 *   // invariants to hold
 *   useHook(ref, obj);
 * }
 *
 * // defined elsewhere
 * function useHook(someRef, obj) {
 *   useEffect(
 *     () => assert(someRef.current === obj),
 *     [someRef, obj]
 *   );
 * }
 * ```
 */
function PrunedNonReactive() {
  const obj = makeObject();
  useIdentity(null);
  mutate(obj);

  useEffect(() => print(obj.value), AUTODEPS);
}

Subdomains

Dependencies

  • react
  • shared-runtime

Frequently Asked Questions

What does pruned-nonreactive-obj.js do?
pruned-nonreactive-obj.js is a source file in the react codebase, written in javascript. It belongs to the TestingUtilities domain, Fixtures subdomain.
What functions are defined in pruned-nonreactive-obj.js?
pruned-nonreactive-obj.js defines 1 function(s): PrunedNonReactive.
What does pruned-nonreactive-obj.js depend on?
pruned-nonreactive-obj.js imports 2 module(s): react, shared-runtime.
Where is pruned-nonreactive-obj.js in the architecture?
pruned-nonreactive-obj.js is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/pruned-nonreactive-obj.js (domain: TestingUtilities, subdomain: Fixtures, directory: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies).

Analyze Your Own Codebase

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

Try Supermodel Free