Skip to content

Scoped styles target polish: docs, Vite runtime tests, bundler READMEs - #63

Merged
leonidaz merged 7 commits into
mainfrom
cursor/scoped-styles-target-polish-c786
Sep 5, 2026
Merged

leonidaz merged 7 commits into
mainfrom
cursor/scoped-styles-target-polish-c786

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #49.

Target-facing follow-up to the sibling-scoped <style> / $class / apply work already on feat/scoped-styles-apply. Core still applies through createJsxTransform; this PR adds docs, bundler README wording, and Vite runtime proof for React, Preact, Solid, and Vue.

Docs

  • Getting Started now shows apply / $class on the React, Preact, Solid, and Vue Vite pages (React uses className; the others use class), with a link to Style composition.
  • New Rspack and Turbopack plugin READMEs describe sibling-scoped <style> emission. Bun READMEs already used that wording.

Runtime tests

  • packages/vite-plugin-*/tests/scoped-styles.runtime.test.tsrx mounts a theme module + applier module and asserts computed colors (local rule wins; $class opt-in still gets the theme) and <style> order (theme sheet before applier sheet).
  • Import-cycle case from D13 layer 3: an applier evaluated before its imported theme reads theme.$class while the theme is uninitialized. Native ESM would throw ReferenceError; Vite's transform binds the cycle as undefined and throws TypeError.

Vite CSS import order

The runtime tests found that each Vite plugin prepended the virtual CSS import, so a module's stylesheet evaluated before its imported themes and equal-specificity local rules lost. The four Vite plugins now emit that import after existing JS imports. Patch changeset included.

Validation

  • vitest run --project tsrx-react-runtime --project tsrx-preact-runtime --project tsrx-solid-runtime --project tsrx-vue-runtime --project vite-plugin-react --project vite-plugin-preact --project vite-plugin-solid --project vite-plugin-vue: 22 files, 277 tests passed.
  • Focused apply suites: 4 files, 8 tests passed.
Open in Web Open in Cursor 

@vercel

vercel Bot commented Sep 4, 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:12pm UTC
tsrx-website-mcp Ready Ready Preview Sep 5, 2026 6:12pm UTC

Request Review

@cursor

cursor Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@leonidaz — ready for your review when you have a minute. Implements #49 (scoped-styles target polish: docs, Vite runtime tests, bundler READMEs).

@leonidaz

leonidaz commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

i think the style documentation might already by covered by #53
I'll keep this open and compare later. the missing readme are nice.

@leonidaz

leonidaz commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

ah, this is actually against #53 didn't notice that. ok, if we end up merging it then.

@cursor

cursor Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

READY FOR REVIEW

Base automatically changed from feat/scoped-styles-apply to main September 5, 2026 17:57
cursoragent and others added 6 commits September 5, 2026 14:05
The shared features page already covers themes. Getting Started now shows
the same apply and $class patterns per target, with className on React
and class on Preact, Solid, and Vue.

Co-authored-by: Jon Wheeler <[email protected]>
Rspack and Turbopack plugins had no README. Add usage notes that match
the Bun plugins and call the emitted CSS sibling-scoped.

Co-authored-by: Jon Wheeler <[email protected]>
Mount a theme module plus applier in React, Preact, Solid, and Vue and
assert computed colors plus stylesheet order. Also lock the D13 layer 3
cycle: an applier evaluated before its imported theme throws
ReferenceError when it reads theme.$class.

Co-authored-by: Jon Wheeler <[email protected]>
Prepending the virtual CSS import evaluated a module's stylesheet before
its imported themes, so equal-specificity local rules lost the cascade.
Emit the CSS import after existing imports so theme sheets land first.

Co-authored-by: Jon Wheeler <[email protected]>
Solid and Vue rewrite .tsrx tests to virtual ids, so fixture imports go
through aliases. The D13 cycle still fails the import; Vite binds the
uninitialized theme as undefined and throws TypeError instead of
ReferenceError.

Co-authored-by: Jon Wheeler <[email protected]>
@leonidaz
leonidaz removed the request for review from trueadm September 5, 2026 18:08
…docs

The getting-started snippets now show the theme module they import, so
"Green: opted in" matches the theme they apply, and the prose uses the
Style composition wording (a theme with $class, the local rule wins at
equal specificity). The Rspack Solid README paragraph no longer breaks
into a list, and the Vite changeset says why the import moves.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@leonidaz
leonidaz force-pushed the cursor/scoped-styles-target-polish-c786 branch from 3bfe058 to 7cbd703 Compare September 5, 2026 18:11
@leonidaz
leonidaz merged commit 1009f58 into main Sep 5, 2026
11 checks passed
@leonidaz
leonidaz deleted the cursor/scoped-styles-target-polish-c786 branch September 5, 2026 18:15
@github-actions github-actions Bot mentioned this pull request Sep 5, 2026
leonidaz added a commit that referenced this pull request Sep 5, 2026
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]>

This branch was successfully deployed

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

Scoped styles follow-up: React/Preact/Solid/Vue docs, runtime tests, and bundler READMEs

3 participants