ENG-12682 Add opt-in React Compiler support

Merged
FA
5d ago
+650-19

Add experimental, opt-in React Compiler support for generated components. Existing apps retain the current build and memoization behavior by default.

config = rx.Config(app_name="my_app", react_compiler=True)

REFLEX_REACT_COMPILER=true provides the equivalent environment setting. The compiler runs before React Router in development and production, targeting React 19 with normal inference and correctness bailouts. Scope is limited to generated app/, app_components/, and utils/components/ JavaScript/JSX; runtime state providers, event utilities, dependencies, and custom public assets are excluded.

The flag installs pinned Babel/compiler development dependencies through the existing dependency cache. Disabling it removes the transform and optional dependencies when no longer needed. The Vite plugin prebundles react/compiler-runtime, which is injected after dependency scanning, to prevent first-load HTTP 504 errors.

Validation:

  • Compiler off/on × development/production browser coverage: 40 passed, 2 skipped. Covers handler arguments, controlled inputs, recursive components, keyed row identity, filtered arrays, and hot reload of an optimized component without losing state. The two skips inspect development-only source modules.
  • Unit suite: 9,722 passed, 18 skipped, 1 deselected; 74.02% coverage. The deselected test is test_run_granian_backend_refuses_requests_while_the_app_is_broken: it also fails on clean upstream 7cac2faf9 (recovery assertion there, refusal assertion on this run). The backend implementation and that test are unchanged by this PR.
  • Repository Ruff checks/formatting, Pyright, and every applicable pre-commit hook passed, including stub generation, ty, and Biome formatting.
  • Disabled Vite output matches the previous template byte-for-byte across 32 existing flag combinations.

Runtime gains depend on the workload; list-heavy updates can regress and compilation adds build time/memory. Documentation makes these tradeoffs explicit. This PR preserves existing Reflex memoization and does not include the fixture-specific filter-callback rewrite from the performance experiment.