Skip to content

fix(core): keep every selector of assigned style blocks (#248, #249, #250) - #251

Merged
leonidaz merged 2 commits into
mainfrom
fix/theme-class-destructure-248
Sep 24, 2026
Merged

leonidaz merged 2 commits into
mainfrom
fix/theme-class-destructure-248

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #248. Fixes #249. Fixes #250.

The rule

An assigned <style> block keeps every selector. It is always a theme and is never pruned. This is what RFC #1 states under "Pruning under apply": "an assigned block keeps all its selectors, each scoped under its own $class hash, because apply can attach that hash anywhere."

Root cause

The same RFC section added a dead-CSS carve-out: a block that is neither exported nor applied "keeps today's class-map pruning". That pruning dates from 0994c17 (#1262), from before themes existed, when const styles = <style> could only be read through class entries. The $class addendum then made a block a theme only when a static check saw a theme.$class read (is_class_read).

$class is an ordinary string. Any path the check couldn't see left the block a class map, and its element rules were emitted only as /* (unused) … */ comments, with no diagnostic, while the element still carried the hash class. Examples:

Whether an element receives $class is ordinary JavaScript data flow, so no static check can decide it.

Changes

Assigned blocks are never pruned:

  • style-analyze.js: every assigned block gets styleKind: 'theme'. The classification (collect_exported_names, is_class_read) and its styleExported / styleClassRead metadata are removed.
  • scoping.js: prepare_stylesheet_for_render prunes nothing in any mode. The signature is unchanged; 'class-map' and the boolean form now render as 'theme', so a consumer passing them can't prune an assigned block.
  • style-ref.js: mark_class_map_selectors and the class_map_selector stamp, which only fed pruning, are removed.
  • Both core transform call sites pass 'theme' for assigned blocks.

Consumers: Ripple (@tsrx/ripple style-scopes.js) and Octane (style-scopes.js) both pick the render mode with styleKind === 'theme' ? 'theme' : 'class-map', so they keep every selector after bumping @tsrx/core, with no code change.

Output change: an element that carries a class entry (styles.card) also carries the hash, so the block's element rules now match it. .card still beats div on specificity.

#250, createScopes: value as T, value!, value satisfies T, and fn<T> are now references. The reference visitor skipped every identifier whose parent was a TS* node, which also dropped these runtime reads. Type positions (typeof value) are still excluded. With the rule above this no longer affects styles, but binding.references is public API that Ripple and Octane use.

Docs: llms.txt, spec 4.5.3 and the metadata appendix, the features page, the core README, the MCP docs index, and the conformance fixture README now state the rule. The assigned-positions conformance fixture expects nothing pruned.

Verification

  • const theme = <style>div { color: red; }</style>; const { $class: cls } = theme; now emits div.<hash> { color: red; } on React, Preact, Solid, Vue, and Hono. It was /* (unused) … */ before.
  • A shared per-target test covers destructuring, alias, holding object, iterated array, prop to a component, return from a helper, and theme!. The analyzer tests assert styleKind: 'theme' in every position. A createScopes test covers the TS wrappers; it fails without the scope change.
  • pnpm test (118 files, 5527 tests), pnpm typecheck, pnpm format:check, and pnpm changeset:check pass.

Release note

@tsrx/core is minor: the language rule changes (more CSS is emitted), and the public styleExported / styleClassRead metadata and the ClassMapCollectionState type are removed. @tsrx/mcp is patch for the regenerated docs.

Downstream

Ripple and Octane pick their render mode from styleKind, so they get the rule from a @tsrx/core bump. Each has a follow-up issue listing the tests and docs that assert class-map pruning. I found them by running each repo's suite against this branch.

Both repos also drop a style block's CSS from the SSR response when $class is read outside a render. Once pruning is gone, that gap is the remaining way these patterns render unstyled on first paint: Ripple-TS/ripple#1515 (any module-level read) and octanejs/octane#1310 (an imported theme read at module scope).

🤖 Generated with Claude Code

@vercel

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

Request Review

leonidaz and others added 2 commits September 24, 2026 13:44
An assigned `<style>` block was a class map unless it was exported,
applied, or read as `theme.$class`, and a class map commented out its
element and descendant rules. `$class` is an ordinary string, so any
path the static check could not see (destructuring, a holding object, a
prop, a return value, iteration) dropped the styles while the element
still carried the hash class.

RFC #1 states the rule: an assigned block keeps all its selectors,
because `apply` and `$class` can attach its hash anywhere. The
dead-CSS carve-out that kept pre-RFC class-map pruning for local blocks
is removed:

- the analyzer marks every assigned block `styleKind: 'theme'` and drops
  the classification-only `styleExported` and `styleClassRead` metadata;
- `prepare_stylesheet_for_render` prunes nothing in any mode, so the
  `'class-map'` mode and the boolean form render as `'theme'` for
  consumers that still pass them;
- the class-map selector marking that only served pruning is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`createScopes` skipped every identifier whose parent was a TypeScript
node, which also dropped the value-level wrappers `value as T`,
`value!`, `value satisfies T`, and `fn<T>`. These read the binding at
runtime, so they now count as references; type positions such as
`typeof value` still do not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@leonidaz
leonidaz force-pushed the fix/theme-class-destructure-248 branch from 2b4deb7 to 26b7c3e Compare September 24, 2026 17:44
@leonidaz leonidaz changed the title fix(core): follow $class reads through destructuring and holding objects (#248) fix(core): keep every selector of assigned style blocks (#248, #249, #250) Sep 24, 2026
@leonidaz
leonidaz merged commit dcc53cb into main Sep 24, 2026
11 checks passed
@leonidaz
leonidaz deleted the fix/theme-class-destructure-248 branch September 24, 2026 19:24
@github-actions github-actions Bot mentioned this pull request Sep 24, 2026

This branch was successfully deployed

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

1 participant