Skip to content

fix(extractor): report Emotion code left at runtime as located errors - #904

Merged
owjs3901 merged 1 commit into
mainfrom
fix/emotion-build-errors
Nov 14, 2026
Merged

owjs3901 merged 1 commit into
mainfrom
fix/emotion-build-errors

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

Emotion code that the build can't compile now fails with a located build error instead of silently staying at runtime (#682). Emotion's cx also composes known classes in argument order.

  • EMO-11 / SC-11: Section.withComponent(make()) on a styled component the file defines is a located error. Section compiles to a plain function, so keeping the call made the module throw when it loaded. other.withComponent(...) on an unknown object is still left alone. The retarget test drops the Kept line, and a new rstest covers the error with the exact message and location. The make() filter in retained_render_assertions::retarget is gone.
  • EMO-05: an @emotion/react import with no Devup UI equivalent (ThemeContext, withEmotionCache, a default import, import * as E) is a located error that names the export. Before this it was an eprintln! warning, and @emotion/react stayed a runtime dependency. Type-only imports still pass.
  • EMO-16 part 2: @emotion/css/create-instance is a located error while @emotion/css is aliased. This covers every way it can be loaded: import, export … from, export *, require(), import x = require() and import(). The new module_loads helper finds these (the vanilla-extract PR adds the same file).
  • EMO-16 part 1: confirmed real. cx(blue, red) came out as "a-b a-a", so stylesheet order decided and blue won. cx now composes its arguments like css() composition when at least one argument is a class css() gave. Class maps are lowered to conditions, so cx(blue, on && red, 'ext', { picked: true }) merges with later wins. A template literal, a computed class-map key, or a class map nested inside an array or condition still uses the old join path.
  • Docs: limitations no longer lists withComponent(make()) under "cascade decides" or merge as not compiled, and it lists the new errors. The migration/overview page no longer says the package can always be dropped.

New build errors:

  • `withComponent()` cannot use `make()` at build time: …
  • `@emotion/react` has no Devup UI equivalent of `ThemeContext` …
  • `@emotion/css/create-instance` creates an Emotion instance at runtime …

Refs #689
Refs #690

Test plan

  • cargo test -p extractor --lib -- emotion import_alias css_prop styled module_loads cx (3451 passed)
  • New snapshots reviewed: emotion_cx_merges_known_styles_in_order, emotion_runtime_imports_are_located_errors. One existing snapshot changed: emotion_cx_takes_class_names, where only the class order inside b differs.
  • cargo clippy -p extractor --all-targets -- -D warnings, cargo fmt --all
  • CI: full test suite + tarpaulin 100%

🤖 Generated with Claude Code

- `Section.withComponent(make())` on a styled component the file defines
  is a located build error: the component compiles to a plain function, so
  the kept call threw when the module loaded
- an `@emotion/react` import with no Devup UI equivalent (`ThemeContext`,
  `withEmotionCache`, default or namespace) is a located error naming the
  export instead of an eprintln warning that kept the package
- `@emotion/css/create-instance` loaded by an import, re-export,
  `require()` or `import()` is a located error while `@emotion/css` is
  aliased
- Emotion's `cx` composes classes `css()` gives by their styles, so
  `cx(blue, red)` is red (last wins) instead of following stylesheet order
- docs: limitations and migration overview match the new behavior

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
libs/extractor/src/import_alias_visit.rs 100.00% <100.00%> (ø)
libs/extractor/src/lib.rs 100.00% <100.00%> (ø)
libs/extractor/src/module_loads.rs 100.00% <100.00%> (ø)
libs/extractor/src/visit.rs 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@owjs3901
owjs3901 merged commit 5dc1c59 into main Nov 14, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant