Skip to content

fix: bundle React Compiler runtime into dist - #8323

Draft
siddharthkp wants to merge 2 commits into
mainfrom
fix-bundle-react-compiler-runtime
Draft

fix: bundle React Compiler runtime into dist#8323
siddharthkp wants to merge 2 commits into
mainfrom
fix-bundle-react-compiler-runtime

Conversation

@siddharthkp

@siddharthkp siddharthkp commented Aug 19, 2026

Copy link
Copy Markdown
Member

Compiled Primer modules emit a bare import { c } from 'react-compiler-runtime' (React Compiler target: '18'). Because that package is externalized, a callable c must be resolved from the consumer's environment. When it can't be, the downleveled (0, l.c)(...) throws:

TypeError: (0 , l.c) is not a function
  at @primer/react/dist/FeatureFlags/FeatureFlags.js

This PR aliases the compiler's react-compiler-runtime import to a small local ESM shim (src/utils/react-compiler-runtime.ts) bundled into @primer/react, so only the c helper travels inside Primer's own module graph (clean ESM, no CommonJS interop, no dependency on consumer resolution). The shim mirrors upstream semantics: prefer React's built-in compiler runtime (React 19+), else a useMemo-backed cache.

It also anchors the rolldown external match to a package-name boundary so react no longer matches react-compiler-runtime (which otherwise made it impossible to opt the runtime out of externalization).

Changelog

Changed

  • Bundle the React Compiler memo helper (c) via a local ESM shim instead of importing the external react-compiler-runtime package.

Rollout strategy

  • Patch release

Testing & Reviewing

  • Reproduced the exact error by transpiling the published dist/FeatureFlags/FeatureFlags.js to CJS and running it against missing/stub/interop-mismatched runtimes.
  • Confirmed via targeted rolldown builds that the alias inlines only the shim as clean ESM (no require/__toESM interop), vs bundling the whole CJS package.

Note: a full npm run build could not complete locally due to pre-existing, unrelated issues (workspace symlinks for local rolldown-plugin-* packages, and a yargs ESM failure in type-css-modules). Relying on CI to confirm the full build + downstream integration.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Storybook)
  • Changes are SSR compatible
  • (GitHub staff only) Integration tests pass at github/github-ui

Compiled modules import a bare 'react-compiler-runtime' specifier; externalizing it makes a callable 'c' depend on the consumer env, which crashes with '(0, l.c) is not a function' when it can't be resolved. Bundle the runtime into dist so it is self-contained.
@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: de8b3d3

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 staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Aug 19, 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.

Alias 'react-compiler-runtime' to a local ESM shim exporting only 'c', instead of bundling the whole CommonJS package (dead code + require interop). Also anchor the external regex to a name boundary so 'react' no longer matches 'react-compiler-runtime' (which made externalization impossible to opt out of).
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 staff Author is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant