fix: bundle React Compiler runtime into dist - #8323
Draft
siddharthkp wants to merge 2 commits into
Draft
Conversation
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 detectedLatest commit: de8b3d3 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 |
Contributor
|
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Compiled Primer modules emit a bare
import { c } from 'react-compiler-runtime'(React Compilertarget: '18'). Because that package is externalized, a callablecmust be resolved from the consumer's environment. When it can't be, the downleveled(0, l.c)(...)throws:This PR aliases the compiler's
react-compiler-runtimeimport to a small local ESM shim (src/utils/react-compiler-runtime.ts) bundled into@primer/react, so only thechelper 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 auseMemo-backed cache.It also anchors the rolldown
externalmatch to a package-name boundary soreactno longer matchesreact-compiler-runtime(which otherwise made it impossible to opt the runtime out of externalization).Changelog
Changed
c) via a local ESM shim instead of importing the externalreact-compiler-runtimepackage.Rollout strategy
Testing & Reviewing
dist/FeatureFlags/FeatureFlags.jsto CJS and running it against missing/stub/interop-mismatched runtimes.require/__toESMinterop), vs bundling the whole CJS package.Note: a full
npm run buildcould not complete locally due to pre-existing, unrelated issues (workspace symlinks for localrolldown-plugin-*packages, and ayargsESM failure intype-css-modules). Relying on CI to confirm the full build + downstream integration.Merge checklist