Skip to content

Fix feature flags compiler runtime issue - #8234

Open
TylerJDev wants to merge 3 commits into
mainfrom
tylerjdev/fix-featureflags-compiler-runtime-skew
Open

Fix feature flags compiler runtime issue#8234
TylerJDev wants to merge 3 commits into
mainfrom
tylerjdev/fix-featureflags-compiler-runtime-skew

Conversation

@TylerJDev

@TylerJDev TylerJDev commented Jul 25, 2026

Copy link
Copy Markdown
Member

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 exports c with identical semantics. It prefers React's built-in compiler runtime (React.__COMPILER_RUNTIME.c, React 19+) and falls back to a useMemo-backed cache otherwise; and imports react as a normal ES module. Because the helper now travels inside Primer's own chunk, a stale Primer chunk carries its own working c and can no longer skew against a separately-cached runtime.

Note: This prevents the crash for future chunk loads. It does not retroactively repair browsers already holding stale pre-fix chunks - those clear via normal cache expiry. A complementary app-side mitigation (keeping react-compiler-runtime in an always-loaded entry chunk) is being tracked separately with the platform owners.

Changelog

New

  • Local ESM shim src/utils/react-compiler-runtime.ts that provides the React Compiler c memo-cache helper, bundled into the package output.
  • Unit test for the shim (src/utils/__tests__/react-compiler-runtime.test.tsx).

Changed

  • rolldown.config.ts now 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 so react no longer matches react-compiler-runtime.
  • script/react-compiler.mjs excludes the shim from React Compiler processing (it backs the compiler runtime).
  • react-compiler-runtime moved from dependencies to devDependencies (it is no longer referenced by the published output; still used by tests/Storybook).

Removed

  • The external, cross-chunk import { c } from 'react-compiler-runtime' from the published build output.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Bug fix with no public API change and no visual change.

Testing & Reviewing

  • No visual/behavioral change to components; FeatureFlags behavior is unchanged.
  • Added unit coverage asserting c(n) returns an n-length cache seeded with the react.memo_cache_sentinel symbol and is stable across re-renders.
  • Verified in the built output that FeatureFlags.js imports c from the bundled shim (../utils/react-compiler-runtime.js) and the shim imports react as clean ESM (no require/__require), and that no bare react-compiler-runtime import remains anywhere in dist.
  • Manually validated by packing the tarball and rendering FeatureFlags in a consumer that has no react-compiler-runtime installed - it renders successfully.
  • Existing FeatureFlags and consumer tests (ActionMenu, AnchoredOverlay, etc.) continue to resolve react-compiler-runtime via devDependencies.

@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0715461

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

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

@github-actions github-actions Bot added the staff Author is a staff member label Jul 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jul 25, 2026
@github-actions
github-actions Bot temporarily deployed to storybook-preview-8234 July 25, 2026 00:16 Inactive
@siddharthkp siddharthkp self-assigned this Aug 19, 2026
@siddharthkp
siddharthkp marked this pull request as ready for review August 20, 2026 13:34
@siddharthkp
siddharthkp requested a review from a team as a code owner August 20, 2026 13:34
@siddharthkp
siddharthkp requested review from siddharthkp and a lite review from Copilot August 20, 2026 13:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-runtime shim (c + hook-backed fallback) and unit tests for the fallback semantics.
  • Updated the Rolldown build config to alias react-compiler-runtime to the local shim and keep it bundled (plus tightened the external matching to avoid prefix collisions like react vs react-compiler-runtime).
  • Excluded the shim from React Compiler processing and moved react-compiler-runtime from 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

Comment on lines 64 to +76
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}($|/)`)
})
@primer-integration

primer-integration Bot commented Aug 20, 2026

Copy link
Copy Markdown

Integration test results from github/github-ui PR:

Passed  CI   Passed
Running  VRT   Running
Waiting  Projects   Waiting

@siddharthkp siddharthkp added the integration-tests: skipped manually Changes in this PR do not require an integration test label Aug 21, 2026
@siddharthkp

Copy link
Copy Markdown
Member

The CI one reported back, which is the one I wanted to hear from. Adding integration-tests: skipped manually

@siddharthkp
siddharthkp enabled auto-merge August 21, 2026 10:36
@siddharthkp
siddharthkp added this pull request to the merge queue Aug 31, 2026
@TylerJDev
TylerJDev removed this pull request from the merge queue due to the queue being cleared Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm integration-tests: skipped manually Changes in this PR do not require an integration test staff Author is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants