Fix feature flags compiler runtime issue - #8234
Conversation
🦋 Changeset detectedLatest commit: 0715461 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a runtime crash caused by the React Compiler output importing c from the external CommonJS react-compiler-runtime package, by bundling a local ESM shim into @primer/react and aliasing compiler-emitted imports to that shim during the build.
Changes:
- Added a local
react-compiler-runtimeshim (c+ hook-backed fallback) and unit tests for the fallback semantics. - Updated the Rolldown build config to alias
react-compiler-runtimeto the local shim and keep it bundled (plus tightened the external matching to avoid prefix collisions likereactvsreact-compiler-runtime). - Excluded the shim from React Compiler processing and moved
react-compiler-runtimefrom dependencies to devDependencies.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/utils/react-compiler-runtime.ts | Adds the bundled ESM shim implementing c with a React 19 builtin-runtime preference and useMemo fallback. |
| packages/react/src/utils/tests/react-compiler-runtime.test.tsx | Adds unit coverage for the fallback cache allocation and stability across re-renders. |
| packages/react/script/react-compiler.mjs | Ensures the shim is excluded from React Compiler processing. |
| packages/react/rolldown.config.ts | Aliases react-compiler-runtime to the shim, bundles it, and tightens external dependency matching. |
| packages/react/package.json | Moves react-compiler-runtime to devDependencies as it’s no longer part of published runtime output. |
| package-lock.json | Updates lockfile metadata to reflect the dependency move. |
| .changeset/bundle-react-compiler-runtime.md | Adds a patch changeset describing the bundled shim crash fix. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 6/7 changed files
- Comments generated: 1
- Review effort level: Lite
| const dependencies = [ | ||
| ...Object.keys(packageMetadata.peerDependencies ?? {}), | ||
| ...Object.keys(packageMetadata.dependencies ?? {}), | ||
| ...Object.keys(packageMetadata.devDependencies ?? {}), | ||
| ].map(name => { | ||
| return new RegExp(`^${name}(/.*)?`) | ||
| }) | ||
| ] | ||
| // `react-compiler-runtime` is intentionally not external: it is aliased to a | ||
| // local shim (see `reactCompilerRuntimeAlias`) and bundled into the output. | ||
| .filter(name => name !== 'react-compiler-runtime') | ||
| .map(name => { | ||
| // Anchor the package-name boundary so a dependency name is not treated as a | ||
| // prefix of another (e.g. `react` must not match `react-compiler-runtime`). | ||
| return new RegExp(`^${name}($|/)`) | ||
| }) |
|
Integration test results from github/github-ui PR: |
|
The CI one reported back, which is the one I wanted to hear from. Adding |
Aims to resolve the compiler's react-compiler-runtime import to a small local ESM shim that is bundled into
@primer/react's own module graph, instead of an external CommonJS dependency. The shim exportscwith identical semantics. It prefers React's built-in compiler runtime (React.__COMPILER_RUNTIME.c, React 19+) and falls back to auseMemo-backed cache otherwise; and importsreactas a normal ES module. Because the helper now travels inside Primer's own chunk, a stale Primer chunk carries its own workingcand can no longer skew against a separately-cached runtime.Changelog
New
src/utils/react-compiler-runtime.tsthat provides the React Compiler c memo-cache helper, bundled into the package output.src/utils/__tests__/react-compiler-runtime.test.tsx).Changed
rolldown.config.tsnow aliases the compiler's react-compiler-runtime import to the local shim and excludes it from the external list so it is bundled. The external match is also anchored to a package-name boundary soreactno longer matches react-compiler-runtime.script/react-compiler.mjsexcludes the shim from React Compiler processing (it backs the compiler runtime).Removed
import { c } from 'react-compiler-runtime'from the published build output.Rollout strategy
Bug fix with no public API change and no visual change.
Testing & Reviewing
n-length cache seeded with thereact.memo_cache_sentinelsymbol and is stable across re-renders.../utils/react-compiler-runtime.js) and the shim importsreactas clean ESM (no require/__require), and that no bare react-compiler-runtime import remains anywhere indist.