Repository navigation
fix(bundlers): emit the module CSS import after its JS imports - #70
Merged
Merged
Conversation
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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merged
This was referenced Sep 23, 2026
Closed
This branch was successfully deployed
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.
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.cssimport after the compiled module instead of prepending it. Directives such as'use client'stay first without the Turbopack directive scanner, which is removed.main.csslists the theme's rule before the applier's. It fails on the old loader.Validation
vitest runfor the nine plugin projects: 9 files, 70 tests passed.tsgo --noEmitfor the nine packages,prettier --checkon 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
.tsrxplugins with the documented theme/apply CSS ordering (already fixed for Vite in #63): the virtual?tsrx-css&lang.cssimport 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.csslists 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.