Registry / web-framework / react-compiler-runtime

react-compiler-runtime

JSON →
library1.0.0jsnpmunverified

react-compiler-runtime is a foundational library that provides the necessary primitives and infrastructure for the experimental React Compiler to operate effectively at runtime. It underpins the compiler's ability to automatically memoize components and hooks, thereby optimizing rendering performance without manual `useMemo` or `useCallback` declarations. The package itself is largely internal, meant to be consumed by the compiled output of the React Compiler rather than directly imported by application developers. As of version 1.0.0, its release cadence is tightly coupled with the development and release cycles of the broader React ecosystem, particularly the React Compiler and React core library (currently React 19 is under active development). Its key differentiator is enabling a future where React applications achieve optimal performance with significantly reduced boilerplate, shifting the responsibility of memoization from the developer to the build toolchain.

npm install react-compiler-runtime
INSTALL
IMPORT
SIG · REACT-COMPILER-RUN
R
react-compiler-runtime
web-frameworkjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

_c
import { c as _c } from 'react-compiler-runtime';
The `_c` symbol (or `c` in some contexts) is an internal hook used by the React Compiler's generated code for memoization. It is not part of the public API and direct usage by application developers is strongly discouraged and prone to breaking changes.
ReactCompilerRuntime
import 'react-compiler-runtime';
While there are no typically exposed named exports for direct application consumption, the package is imported for its side effects or internal polyfills, especially when targeting React versions prior to 19.
createMemoCache
/* No direct import for application developers */
The runtime likely contains internal factories or utilities for creating and managing memoization caches. These are typically consumed by the compiled output or the Babel plugin, not directly by application code. There is no publicly documented `createMemoCache` export.

This quickstart demonstrates a React component with a manually memoized calculation, illustrating the type of optimization the React Compiler and its runtime (react-compiler-runtime) aim to automate.

import React, { useState, useMemo } from 'react'; import ReactDOM from 'react-dom/client'; // This component uses a memoized calculation. // With the React Compiler, the `useMemo` call for `expensiveCalculation` // might be automatically inserted or optimized, relying on the // `react-compiler-runtime` under the hood to manage the memoization cache. function MyOptimizedComponent() { const [count, setCount] = useState(0); const [multiplier, setMultiplier] = useState(2); const expensiveCalculation = useMemo(() => { console.log('Calculating expensive value...'); let result = 0; for (let i = 0; i < 1000000; i++) { result += i; } return result * count * multiplier; }, [count, multiplier]); return ( <div> <h1>React Compiler Runtime Demo</h1> <p>Count: {count}</p> <button onClick={() => setCount(c => c + 1)}>Increment Count</button> <p>Multiplier: {multiplier}</p> <button onClick={() => setMultiplier(m => m + 1)}>Increment Multiplier</button> <p>Expensive Calculation Result: {expensiveCalculation}</p> <p> The React Compiler, enabled by `react-compiler-runtime`, aims to automatically memoize parts of your components, making manual `useMemo` and `useCallback` often unnecessary. This example demonstrates a pattern the compiler would optimize. </p> </div> ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<MyOptimizedComponent />); // To run, save as index.tsx, add react and react-dom to package.json, // and set up a build process (e.g., with Vite or Create React App). // Ensure your build setup includes the React Compiler plugin if you want to // observe its effects beyond this conceptual example.
Debug
Known issues
breakingDirect usage of `react-compiler-runtime` APIs (like the internal `_c` hook) is highly discouraged. Its internal structure is subject to frequent change without adherence to semver, as these APIs are intended for the React Compiler's generated output, not for application developers.
fix
Avoid direct imports or reliance on `react-compiler-runtime`'s internal symbols in application code. Focus on adhering to React's Rules of Hooks and letting the `babel-plugin-react-compiler` handle the optimization.
affects: >=1.0.0
gotchaThe React Compiler (and thus its runtime) is currently experimental. Its behavior, stability, and integration methods are still evolving, and breaking changes or unexpected performance characteristics may occur. Consider its use primarily for libraries or projects that can tolerate this level of churn.
fix
Monitor official React Compiler documentation and release notes. Implement thorough testing for applications or libraries using the compiler to catch regressions.
affects: >=1.0.0
gotchaEnsure your `react` peer dependency (`^17.0.0 || ^18.0.0 || ^19.0.0 || ^0.0.0-experimental`) is met. Mismatched React versions can lead to runtime errors or incorrect compiler behavior, as the runtime is designed to integrate deeply with specific React core functionalities and may polyfill APIs for older versions.
fix
Upgrade or downgrade your `react` and `react-dom` packages to satisfy the peer dependency range, e.g., `npm install react@latest react-dom@latest`.
affects: >=1.0.0
deprecatedThe `eslint-plugin-react-hooks` package, closely related to the compiler ecosystem, saw a `component-hook-factories` rule accidentally removed in v7.1.0 and then re-added as a deprecated no-op in v7.1.1. This indicates the rapid evolution of tooling around the React Compiler and the need to keep related packages up-to-date.
fix
Always use the latest stable version of `eslint-plugin-react-hooks` and `eslint-plugin-react-compiler` to ensure you have the most up-to-date linting rules and compiler integration.
affects: 7.1.0
Errors
Common errors & fixes
Module not found: Can't resolve 'react-compiler-runtime'
The `react-compiler-runtime` package is not installed or incorrectly referenced in your project's build configuration. This is common when setting up the React Compiler.
fix
`npm install react-compiler-runtime` or `yarn add react-compiler-runtime`. For libraries targeting React < 19, ensure it's a direct dependency and included in the final bundle.
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
This common React error can occur if the `react-compiler-runtime` or the React Compiler itself is misconfigured, leading to an incorrect build output that violates React's Rules of Hooks.
fix
Verify your React Compiler setup, ensuring proper transpilation and React version compatibility in your Babel/Vite configuration. Check your `react` and `react-dom` versions. Ensure your code adheres to React's Rules of Hooks.
Peer dependency 'react' (^17.0.0 || ^18.0.0 || ^19.0.0 || ^0.0.0-experimental) not met.
Your installed React version does not satisfy the `react-compiler-runtime`'s peer dependency requirements, which can lead to instability or undefined behavior.
fix
Upgrade or downgrade your `react` and `react-dom` packages to match the required range, e.g., `npm install react@latest react-dom@latest` or `npm install react@18 react-dom@18`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
reactrequiredRequired as a peer dependency for the runtime to integrate with React's core functionalities, enabling automatic memoization. Supports React 17, 18, and 19.
Agent activity
9 hits · last 30 days
node
8
Resources
react-compiler-runtime — npm install react-compiler-runtime · libregistry