fix(emotion): Handle React Compiler output without panicking - #636
Conversation
React Compiler can leave generated Emotion calls at BytePos(0), which makes pure comments and source map lookup panic. Skip those location-only bits when the span is synthetic and add a small wasm regression. Co-authored-by: Codex <noreply@openai.com>
🦋 Changeset detectedLatest commit: f83c16d 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 |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
keep the fixture to the smallest JSX case we need here. Co-authored-by: Codex <noreply@openai.com>
| "devDependencies": { | ||
| "@changesets/cli": "^2.27.1", | ||
| "@swc/core": "^1.15.40", | ||
| "@swc/core": "^1.15.43", |
There was a problem hiding this comment.
needed so the wasm test actually exercises reactCompiler; 1.15.40 rejects the option before it reaches the plugin.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69eede5ee8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| let hash = if program.span().lo == BytePos(0) { | ||
| 0 |
There was a problem hiding this comment.
Preserve a unique hash for dummy-span programs
When program.span().lo is BytePos(0), this now passes 0 as src_file_hash; create_label_prop_node uses that value to build every styled target class (e{hash}{count}). Any React-Compiler/SWC pipeline that gives the Program a dummy span but still contains styled(...) calls will therefore emit the same e00, e01, ... targets for unrelated files, so component selectors can match the wrong components. The fallback should still derive a per-file/source hash instead of using a constant.
Useful? React with 👍 / 👎.
drop the dummy program span fallback so styled target hashes stay on the existing path. also adds the patch changeset for the plugin fix. Co-authored-by: Codex <noreply@openai.com>
React Compiler can leave generated Emotion calls with dummy spans, then @swc/plugin-emotion panics trying to attach comments/source maps at BytePos(0).
This keeps normal Emotion output untouched and only skips pure comments/source maps when there is no real source position to attach them to.
minimal reproduction of panic in rspack/swc: https://github.com/scttcper/swc-react-compiler-plugins