#1516·ripple

Adopt @tsrx/core's rule that assigned style blocks keep every selector (tsrx-org/tsrx#251)

Author: leonidazCreated Sep 24, 2026Updated Sep 24, 2026

Issue Category

Other

Bug Description

Upstream change to adopt. tsrx-org/tsrx#251 (fixes tsrx-org/tsrx#248, #249 and #250) changes one rule in @tsrx/core: an assigned <style> block (const theme = <style>…</style>) is always a theme, and none of its selectors are pruned.

Until now, a block that wasn't exported, applied, or read as theme.$class was treated as a class map, and its element and descendant rules were commented out as /* (unused) … */. That check couldn't see $class travelling through ordinary JavaScript: destructuring, a holding object, a prop, a return value, or iteration. In those cases the styles silently disappeared while the element still carried the hash. The #248 repro loses its div rule in the Ripple playground today.

What the new core does:

  • metadata.styleKind: now 'theme' on every assigned block. metadata.styleExported and metadata.styleClassRead are removed.
  • prepareStylesheetForRender: prunes nothing in any mode. The 'class-map' mode and the boolean form render as 'theme'.
  • Visible effect: an element that carries a class entry (styles.card) also carries the hash, so the block's element rules now match it. The class rule still wins on specificity.

The fix is released as a @tsrx/core minor (0.4.0 expected), so the ^0.3.3 catalog pin won't pick it up automatically.

Reproduction Steps

I checked what the new core breaks. On main at 83ed56159, I pointed @tsrx/core (root, ripple, tsrx-ripple, vite-plugin) at the tsrx-org/tsrx#251 branch and ran pnpm vitest run. The baseline with 0.3.3 was 181 files and 2376 tests passing. With the #251 core, exactly 4 tests fail, all asserting class-map pruning:

FAIL |ripple-client| packages/ripple/tests/client/css/scoped-styles.test.tsrx > $class and apply > keeps every selector of a theme and only class selectors of a plain class map
FAIL |ripple-client| packages/ripple/tests/client/css/style-identifier.test.tsrx > style class maps > compiler output > prunes style expression selectors the class map cannot reach in client mode
FAIL |ripple-client| packages/ripple/tests/client/css/style-identifier.test.tsrx > style class maps > compiler output > prunes style expression selectors the class map cannot reach in server mode
FAIL |ripple-server| packages/ripple/tests/server/style-identifier.test.tsrx > style class maps (server) > server compiler output > prunes style expression selectors the class map cannot reach

The scoped-style conformance suite (packages/tsrx-ripple/tests/scoped-styles.test.js) passes unchanged. It loads the fixtures from @tsrx/core/test-harness, and assigned-positions now expects nothing pruned.

Environment

  • OS: macOS 26.6.2
  • Browser: n/a
  • Ripple Version: 0.4.7 (main at 83ed56159)
  • Node Version: 24.18.0

Additional Context

To do once the @tsrx/core release with tsrx-org/tsrx#251 is published:

  1. Bump @tsrx/core in the catalog (pnpm-workspace.yaml) and the lockfile.

  2. Update the 4 tests above to expect every selector kept: div.<hash>, .parent.<hash> .card:where(.<hash>), and body from :global(body), with no (unused) comments.

  3. Update the docs that describe class-map pruning:

    • website/docs/guide/styling.md, the "A local block used only through its class keys is a plain class map … removed as unused" paragraph;
    • website-new/public/llms.txt, the theme / class-map bullets under "Assigning a <style> block";
    • website/docs/best-practices.md and the rulesync source .rulesync/rules/project.md, which regenerates AGENTS.md, CLAUDE.md, GEMINI.md and the Copilot instructions.

    The rule to state: every assigned block keeps every selector, and elements that carry a class entry also match its element rules.

  4. Optional cleanup: style-scopes.js#L666 can pass 'theme' directly. The current styleKind === 'theme' ? 'theme' : 'class-map' already gives 'theme' with the new core.

  5. Changeset: note the output change. Element and descendant rules of local assigned blocks are now emitted, and they apply to elements that carry the block's class entries.

Related: Ripple-TS/ripple#1515. With pruning gone, the SSR registration gap there is the remaining way a module-level $class read renders unstyled on first paint.

Checklist

  • I've searched for existing issues
  • I'm willing to help implement a fix