Skip to content

fix(tsrx): keep sibling-combinator rules at the top of a style scope - #73

Merged
leonidaz merged 1 commit into
mainfrom
fix/prune-sibling-container
Sep 6, 2026
Merged

leonidaz merged 1 commit into
mainfrom
fix/prune-sibling-container

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

.a + .b and .a ~ .c between the items of a style scope (or of a control-flow branch fragment) were pruned as unused by every target, although both elements carry the scope hash and the rule matches at runtime.

Cause. prune_css looked up siblings through get_element_parent, the nearest ancestor element on the path. The RFC #1 pre-pass prunes each scope against its items with an empty root path (the container must stay invisible to ancestor combinators), so top-level items had no element parent and no siblings. Items of a <>…</> inside a branch had the same problem, since the fragment was skipped too.

Fix.

  • prune_css reads the element's actual children list (element or fragment) for + / ~, via a new get_sibling_container. Ancestor combinators keep using get_element_parent, so a scope's container is still never matched.
  • The style pre-pass seeds each scope's paths with a synthetic root fragment holding the list's items. createScopeRoot is exported so consumer compilers with their own collectors (Ripple, Octane) can seed the same root.
  • New conformance fixture sibling-combinators (kept rules at the scope root, inside .wrap, and inside an @if fragment; .f + .g with no .f sibling still pruned), run by every JSX target.

Before, for the fixture: /* (unused) .a + .b … */. After: .a.tsrx-… + .b:where(.tsrx-…).

Follow-ups once released: Ripple-TS/ripple#1441 seeds the root in its own collector; Octane's collectPrunableElements needs the same one-line seed.

🤖 Generated with Claude Code


Note

Medium Risk
Changes core CSS prune matching for +/~ and scope path seeding; behavior is localized but affects all scoped-style targets and downstream compilers that collect prunable elements.

Overview
Fixes incorrect pruning of .a + .b and .a ~ .c when both sides are top-level items in a scoped template or siblings inside a control-flow fragment. Those rules were marked unused because sibling lookup used the nearest ancestor element’s children, so scope-root and fragment children had no discoverable siblings.

prune_css now resolves siblings via get_sibling_container, walking metadata.path to the list that actually contains the node (parent element, authored fragment, or synthetic scope root). Ancestor combinators still use get_element_parent, so scope containers stay invisible to descendant selectors.

The style-scope pre-pass seeds each scope’s element paths with createScopeRoot (exported from @tsrx/core for other compilers). A new sibling-combinators fixture asserts kept rules at scope root, under .wrap, and in an @if fragment, while .f + .g stays pruned when .f is absent.

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

Pruning found an element's siblings only under its nearest ancestor
element, so the items of a scope's root list (which has no element parent
by design) and the items of a branch fragment had no siblings, and their
`+` / `~` rules were commented out as unused although both elements carry
the scope hash at runtime.

- prune_css reads the element's actual children list (element or
  fragment) for sibling combinators; ancestor combinators still only see
  elements, so a scope's container stays unmatched
- the style pre-pass seeds each scope's ancestor paths with a root
  fragment (createScopeRoot, exported for consumer compilers)
- conformance fixture sibling-combinators pins the kept and pruned rules
  for every target

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

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

Request Review

@leonidaz
leonidaz merged commit 5369440 into main Sep 6, 2026
11 checks passed
@leonidaz
leonidaz deleted the fix/prune-sibling-container branch September 6, 2026 00:43
@github-actions github-actions Bot mentioned this pull request Sep 6, 2026
leonidaz added a commit to Ripple-TS/ripple that referenced this pull request Sep 6, 2026
…uning

Picks up tsrx-org/tsrx#73: sibling combinators between the items of a
scope are kept. Ripple's own element collector now roots each scope's
ancestor paths at a fragment holding the list's items (createScopeRoot),
so `+` and `~` between top-level items find their siblings while the
container stays unmatched; the shared sibling-combinators fixture passes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
leonidaz added a commit to Ripple-TS/ripple that referenced this pull request Sep 6, 2026
…1441)

* feat(tsrx-ripple): sibling-scoped style blocks, $class, and apply (TSRX RFC #1)

Implement RFC tsrx-org/RFCs#1 for the Ripple target on @tsrx/core 0.1.66:

- style-scopes pre-pass: scope discovery per children list, per-scope
  pruning, lexical CSS emission order, class stamping (enclosing hashes
  outer first, then applied themes), apply resolution, and assigned-block
  preparation in the analyzer's theme/class-map mode
- client and server transforms read the stamped chain; runtime reads of
  imported themes concatenate at render time; the server registers applied
  themes before the scopes that apply them and groups a scope's sheets
- $class on class maps, self-closing apply bundles, type-only apply checks
- runtime: multi-token #class spreads; output_register_css outside a render
- fix: a @{ } block as the child of a DOM element rendered nothing on the
  client
- tests: shared conformance fixtures, diagnostics, type-level, and client
  and server runtime suites
- docs: styling guide, syntax guide, README, llms.txt, agent rules, and a
  scoped styles & themes playground example; website-new components moved
  to @{ } bodies

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

* docs(styling): add the which-one-to-use table for :global

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

* fix(tsrx-ripple): keep scope classes when a spread brings its own class

A static class with a scope chain on an element that also spreads props
rides through the spread: as `#class` on the client, which the runtime
adds after every other attribute, and through spread_attrs on the server,
so a `class` in the spread cannot drop the scope hashes or an applied
theme, and the server writes one class attribute.

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

* chore: bump @tsrx packages to core 0.1.67 and seed scope roots for pruning

Picks up tsrx-org/tsrx#73: sibling combinators between the items of a
scope are kept. Ripple's own element collector now roots each scope's
ancestor paths at a fragment holding the list's items (createScopeRoot),
so `+` and `~` between top-level items find their siblings while the
container stays unmatched; the shared sibling-combinators fixture passes.

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

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>

This branch was successfully deployed

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