Home / File/ fast-refresh-refresh-on-const-changes-dev.js — react Source File

fast-refresh-refresh-on-const-changes-dev.js — react Source File

Architecture documentation for fast-refresh-refresh-on-const-changes-dev.js, a javascript file in the react codebase. 2 imports, 0 dependents.

File javascript TestingUtilities Fixtures 2 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  ffc0147c_6b5a_3942_bb71_d73a6d88eb43["fast-refresh-refresh-on-const-changes-dev.js"]
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  ffc0147c_6b5a_3942_bb71_d73a6d88eb43 --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  006eec3d_77a9_4a47_e6c1_a96d7a6c9c05["shared-runtime"]
  ffc0147c_6b5a_3942_bb71_d73a6d88eb43 --> 006eec3d_77a9_4a47_e6c1_a96d7a6c9c05
  style ffc0147c_6b5a_3942_bb71_d73a6d88eb43 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// @compilationMode:"infer" @enableResetCacheOnSourceFileChanges @validateExhaustiveMemoizationDependencies:false
import {useEffect, useMemo, useState} from 'react';
import {ValidateMemoization} from 'shared-runtime';

let pretendConst = 0;

function unsafeResetConst() {
  pretendConst = 0;
}

function unsafeUpdateConst() {
  pretendConst += 1;
}

function Component() {
  useState(() => {
    // unsafe: reset the constant when first rendering the instance
    unsafeResetConst();
  });
  // UNSAFE! changing a module variable that is read by a component is normally
  // unsafe, but in this case we're simulating a fast refresh between each render
  unsafeUpdateConst();

  // TODO: In fast refresh mode (@enableResetCacheOnSourceFileChanges) Forget should
  // reset on changes to globals that impact the component/hook, effectively memoizing
  // as if value was reactive. However, we don't want to actually treat globals as
  // reactive (though that would be trivial) since it could change compilation too much
  // btw dev and prod. Instead, we should reset the cache via a secondary mechanism.
  const value = useMemo(() => [{pretendConst}], [pretendConst]);

  return <ValidateMemoization inputs={[pretendConst]} output={value} />;
}

export const FIXTURE_ENTRYPOINT = {
  fn: Component,
  params: [{}],
  sequentialRenders: [{}, {}],
};

Subdomains

Dependencies

  • react
  • shared-runtime

Frequently Asked Questions

What does fast-refresh-refresh-on-const-changes-dev.js do?
fast-refresh-refresh-on-const-changes-dev.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 fast-refresh-refresh-on-const-changes-dev.js?
fast-refresh-refresh-on-const-changes-dev.js defines 3 function(s): Component, unsafeResetConst, unsafeUpdateConst.
What does fast-refresh-refresh-on-const-changes-dev.js depend on?
fast-refresh-refresh-on-const-changes-dev.js imports 2 module(s): react, shared-runtime.
Where is fast-refresh-refresh-on-const-changes-dev.js in the architecture?
fast-refresh-refresh-on-const-changes-dev.js is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fast-refresh-refresh-on-const-changes-dev.js (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