Skip to content

Support styled-components, Emotion, vanilla-extract, and StyleX sources - #669

Merged
owjs3901 merged 1 commit into
mainfrom
owjs3901/css-in-js-compat
Sep 16, 2026
Merged

owjs3901 merged 1 commit into
mainfrom
owjs3901/css-in-js-compat

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Closes #664.

Why

Adopting Devup UI meant rewriting every styling call site first. This teaches the extractor to read the source APIs of styled-components, Emotion, vanilla-extract, and StyleX directly, so an existing codebase builds as-is and can migrate file by file.

What

StyleX

  • Computed member access (styles[variant]) resolved instead of silently dropping the whole style — the StyleX extraction: computed member access is dropped at the call site #664 bug.
  • Remaining surface implemented: defineVars, createTheme, createThemeContract, defineConsts, positionTry, viewTransitionClass, attrs, StyleXArray, optional chaining. UNSUPPORTED_STYLEX_APIS is gone.

styled-components / Emotion

  • styled maps onto Devup's styled in both the curried and two-argument forms. Malformed calls such as styled('div', 'span') are left untransformed.
  • Emotion's Global element is supported, and @emotion/react is a default alias.
  • props.theme interpolation resolves to CSS variables at build time via ThemeProvider, in both template and object form, so theme reads cost no runtime work.

vanilla-extract

  • style / globalStyle map onto css / globalCss.

Packaging

  • Compat-only symbols moved to a separate @devup-ui/react/compat entry, so the main entry keeps exporting Devup's own API. useTheme gets its original name back.
  • Every plugin (next, vite, webpack, rsbuild, bun) now emits compat.d.ts next to the generated CSS to type the source packages.

Robustness

  • 12 to_expression() calls became as_expression(). The former panics on non-expression nodes that these paths can legitimately receive.

Two placements worth a reviewer's eye

Both are load-bearing, not cosmetic — each is documented at its definition:

  • is_vanilla_extract_file moved to utils. Import rewriting needs it in every build, but its old module sits behind the vanilla-extract feature that the lite WASM variant drops.
  • StyledTheme is declared in types/props so styled reaches it over an import edge it already had. Importing it from utils/theme-vars instead adds a new edge that destabilises how DevupProps and DevupCustomShorthands resolve, which drops the selector props (caught by type-tests/custom-shorthand.ts).

Docs

Adds migration guides under docs/migration/: overview, styled-components, vanilla-extract, and StyleX.

Verification

  • cargo test --workspace — 2007 passed
  • cargo clippy --workspace --all-targets --all-features -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • cargo check -p extractor --no-default-features — clean (the lite WASM variant)
  • bun run build — all 11 packages exit 0
  • bun test — 5204 passed
  • bun run verify:dist — all declared dist entry points load and export

@owjs3901
owjs3901 force-pushed the owjs3901/css-in-js-compat branch 2 times, most recently from 553b6bd to 7005ff8 Compare September 15, 2026 14:21
Projects migrating to Devup UI had to rewrite every styling call site
before they could build. The extractor now recognises the source APIs of
those four libraries and rewrites them to Devup equivalents at build
time, so an existing codebase compiles as-is and can migrate file by
file.

- Resolve StyleX computed member access (`styles[variant]`), which
  previously dropped the whole style. Fixes #664.
- Implement the remaining StyleX surface: defineVars, createTheme,
  createThemeContract, defineConsts, positionTry, viewTransitionClass,
  attrs, StyleXArray and optional chaining.
- Map styled-components and Emotion onto `styled`/`css`, including both
  the curried and two-argument call forms, and add the Emotion `Global`
  element.
- Resolve `props.theme` interpolation to CSS variables at build time via
  ThemeProvider, so theme reads cost no runtime work.
- Map vanilla-extract `style`/`globalStyle` onto `css`/`globalCss`.

Compat-only symbols move to a separate `@devup-ui/react/compat` entry so
the main entry keeps exporting Devup's own API, and each plugin emits a
`compat.d.ts` alongside the generated CSS to type the source packages.

Replace 12 `to_expression()` calls with `as_expression()`; the former
panics on non-expression nodes that these code paths can legitimately
receive.

Two placements are load-bearing rather than cosmetic. `is_vanilla_extract_file`
moves to `utils` because import rewriting needs it in every build, while its
old module is behind the `vanilla-extract` feature that the lite WASM variant
drops. `StyledTheme` is declared in `types/props` so `styled` reaches it over
an import edge it already had: pulling it from `utils/theme-vars` instead adds
a new edge that destabilises how `DevupProps` and `DevupCustomShorthands`
resolve, and drops the selector props.
@owjs3901
owjs3901 force-pushed the owjs3901/css-in-js-compat branch from 7005ff8 to 74a6627 Compare September 15, 2026 14:42
@github-actions

Copy link
Copy Markdown
Contributor

Changepacks

@devup-ui/react@1.0.42 - packages/react/package.json

Maybe you forgot to write the following files to the latest version

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
libs/extractor/src/css_utils.rs 100.00% <100.00%> (ø)
.../extractor/extract_global_style_from_expression.rs 100.00% <100.00%> (ø)
...tor/src/extractor/extract_style_from_expression.rs 100.00% <100.00%> (ø)
...tractor/src/extractor/extract_style_from_styled.rs 100.00% <100.00%> (ø)
...tractor/src/extractor/extract_style_from_stylex.rs 100.00% <100.00%> (ø)
libs/extractor/src/import_alias_visit.rs 100.00% <100.00%> (ø)
libs/extractor/src/lib.rs 100.00% <100.00%> (ø)
libs/extractor/src/prop_modify_utils.rs 100.00% <100.00%> (ø)
libs/extractor/src/stylex.rs 100.00% <100.00%> (ø)
libs/extractor/src/util_type.rs 100.00% <100.00%> (ø)
... and 18 more
🚀 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 6222a98 into main Sep 16, 2026
6 of 7 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.

StyleX extraction: computed member access is dropped at the call site

1 participant