Skip to content

fix(bundlers): emit the module CSS import after its JS imports - #70

Merged
leonidaz merged 1 commit into
mainfrom
fix/bundler-css-import-order
Sep 5, 2026
Merged

leonidaz merged 1 commit into
mainfrom
fix/bundler-css-import-order

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #63 and RFC tsrx-org/RFCs#1.

The docs promise that a theme's CSS comes before the CSS of the block that applies it, so the local rule wins at equal specificity. #63 made the four Vite plugins honor that across modules by moving the virtual CSS import after the module's JS imports. The Rspack, Turbopack, and Bun plugins still prepended it, so on those bundlers an imported theme's stylesheet was emitted after the applying module's stylesheet and the theme's rule won.

Changes

  • @tsrx/rspack-plugin-{react,preact,solid,vue}, @tsrx/turbopack-plugin-react, @tsrx/bun-plugin-{react,preact,solid,vue}: append the ?tsrx-css&lang.css import after the compiled module instead of prepending it. Directives such as 'use client' stay first without the Turbopack directive scanner, which is removed.
  • Rspack and Turbopack loaders keep the compiler's source map when a module has styles. Nothing above the import moves, so the map still applies; previously it was dropped.
  • Loader tests in all nine packages assert the CSS import lands after an existing import and the map survives.
  • New Rspack 2 bundle test: a theme module plus an applying module, asserting the emitted main.css lists the theme's rule before the applier's. It fails on the old loader.
  • Patch changeset for the nine packages.

Validation

  • vitest run for the nine plugin projects: 9 files, 70 tests passed.
  • tsgo --noEmit for the nine packages, prettier --check on changed files, pnpm changeset:check.

🤖 Generated with Claude Code


Note

Medium Risk
Changes global CSS emission order for Rspack/Turbopack/Bun builds, which can alter styling where apps depended on the previous (incorrect) cascade; scope is limited to bundler plugins and is covered by new ordering tests.

Overview
Aligns Rspack, Turbopack, and Bun .tsrx plugins with the documented theme/apply CSS ordering (already fixed for Vite in #63): the virtual ?tsrx-css&lang.css import is appended after the compiled module’s JS imports instead of prepended, so imported theme stylesheets enter the graph before the applying module’s scoped CSS and local rules win at equal specificity.

Rspack and Turbopack JS loaders now preserve the compiler source map when a <style> block exists (they no longer discard the map because nothing is injected above the compiled code). Turbopack drops the directive-scanning prepend helper in favor of a simple trailing import; 'use client' and similar directives remain first because they stay in the compiled output.

Tests across all nine plugin packages assert import order (and maps where relevant). Rspack React adds an end-to-end bundle check that main.css lists theme rules before applier rules. A patch changeset covers the nine affected packages.

Reviewed by Cursor Bugbot for commit bc9cfcf. Bugbot is set up for automated code reviews on this repo. Configure here.

The Rspack, Turbopack, and Bun plugins prepended the virtual
`?tsrx-css&lang.css` import, so a module's stylesheet entered the asset
graph before the stylesheets of the themes it imports and a rule in the
applying scope lost to the theme's at equal specificity. Vite got the same
fix in #63; this makes every bundler honor the documented order.

The import now follows the module's own imports. Nothing above it moves,
so the Rspack and Turbopack loaders keep the compiler's source map instead
of dropping it, and the Turbopack directive scanner is no longer needed.

Tests assert the import lands after an existing import in every loader,
and a real Rspack 2 build proves an imported theme's CSS is emitted before
the module that applies it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vercel

vercel Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tsrx-website Ready Ready Preview Sep 5, 2026 6:22pm UTC
tsrx-website-mcp Ready Ready Preview Sep 5, 2026 6:22pm UTC

Request Review

This branch was successfully deployed

2 active deployments
Preview – tsrx-website-mcp — bc9cfcf2 Deployed Sep 5, 2026 by vercel[bot]
Preview – tsrx-website — bc9cfcf2 Deployed Sep 5, 2026 by vercel[bot]
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