Repository navigation
refactor: stop generating @scope around package stylesheets - #4381
Conversation
`page init` wrapped every package sheet in a generated `@scope (<package tags>) to (<foreign widgets>)`, rooted at `:host(...)` in shadow trees, so authors wrote `:scope` for "my widget" and Leaf kept a package's rules off widgets nested inside its own. That generated CSS is what Firefox mis-evaluated in #4295, and it guarded cases nothing exercised: every class the bundled packages name is already package-prefixed. Leaf now places each sheet in its cascade tier and rewrites none of its rules. Package sheets name their widgets: `lf-tabs .lf-tabstrip` in the document, `:host(lf-diff.lf-rendered) .x` in a shadow tree. A codemod made the ~570 `:scope` edits; an authored `@scope (html[data-lf-interactive] :scope)` keeps its native meaning, now rooted at the widget it styles. widget-shadow.css still reaches both trees. The theme-shadow.css role goes: a theme reaches shadow trees through the custom properties they inherit. The diff's palette and geometry no longer load twice, since the document rule already sets them on the host. Behavior: a package's rules now reach a foreign widget nested inside its widgets, which no bundled rule does. Measured by reading 42 computed properties on every element, shadow trees included, across 16 examples in Chromium and 7 in Firefox, main against this change: one value differs. A visual review's capture shot now takes the `margin: 0` its package declares (it had kept 10px from the default package through scope proximity). The diagram's negative end margin lost specificity to the layer's trim of a frame's last margin and now names `:last-child` to keep it. Tests: the contract test for the generated boundary goes with it; the shadow confinement test now writes `:host(lf-own-tree) span` and still runs in every engine; the theme-shadow test goes. No protocol bump: a page vendored earlier keeps its composed sheets, which the runtime doesn't read differently. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # dist/kernel/kernel.json # packages/default/styles/board.css # packages/default/styles/draft.css # packages/default/styles/options.css # packages/default/styles/sample.css # packages/default/styles/shot.css # packages/default/styles/tabs.css # packages/default/widgets.css # packages/diff/styles/widget-shadow.css # packages/diff/widget-shadow.css # packages/file-editor/widget-shadow.css # packages/playground/widgets.css # tests/browser/threads/test_layout.py
Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
[P2] The extending guide still promises the package confinement this change removes. Its nested-widget section and diagram say “The boundary stops selectors, not inheritance” and that review-package rules “stop before” a nested widget’s interior. That is now false: in a Chromium comparison using the composed sheets, a review widget’s descendant-paragraph rule left nested Options text untouched on the base and styled it on this head. Authors following this explanation would rely on isolation Leaf no longer provides.
Update that section’s diagram and caption to explain that the author preserves the nested widget’s presentation with child combinators or owned classes, consistent with the revised package reference and the guidance farther down this page. These remaining edits are outside the diff; I can push the mechanical documentation correction if you’d like.
# Conflicts: # dist/kernel/kernel.json # packages/default/styles/code.css # packages/default/widgets.css
…k by naming structure The extending guide's nested-widget section described the boundary #4381 removes; it now says the outer package keeps its rules off a nested widget's interior by naming its own children and classes.
# Conflicts: # browser/styles/theme.css # packages/default/widgets.css # packages/diff/styles/widget-shadow.css # packages/diff/styles/widgets.css # packages/diff/widget-shadow.css # packages/diff/widgets.css # packages/visual-review/styles/widgets.css # packages/visual-review/widgets.css # src/leaf/layer.py
Since #4381 removed `:scope` from the style query in `packages/playground/widgets.css`, a rich choice group (`.lf-playground-candidates`) ignored `--playground-choice-columns`: the query's selector named only `lf-playground-control > .lf-playground-choices`, which weighs less than the rich default grid, so an author who set two columns on a candidates row still got the auto-fit layout. The query now names the rich control's class too, which ties the default's specificity, and the later rule wins. `test_plain_choices_wrap_between_whole_labels_until_the_author_sets_columns` gains a rich group whose author asks for one column at 60rem; it fails on main and passes here. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude <[email protected]>
Each change keeps the behavior the test protects and moves its assumption to the layer record: - A package selected by path is recorded as the page's copy, `./packages/<name>` (test_page_packages_are_explicit_and_survive_reinitialization, test_an_installed_payload_is_complete_and_launches_outside_the_checkout, test_init_restarts_a_served_page_onto_the_replacement_contract). A re-selection that keeps the page's packages names those copies from where init runs (test_a_re_vendor_waits_for_the_reply_being_written). - A test that changed the vendored registry declares the change on the page instead (`declare_on_page`): diagram part prefixes. A page declaration validates every catalog example, so the card and column recording values no longer make their attributes required, which lf-board's example lacks. - `read_page_data` judges sources against the vocabulary a write takes, the layer with the page's declarations, as it did when those declarations were edits to the vendored registry. - Re-initialization refreshes only an active revision, so the dropped-binding test activates revision 1 under the package that declares the binding. Two were stale on main before this branch: - Package stylesheets are placed unscoped since #4381; the package test now asserts its widget rule reaches the page's defaults tier. - Every commit to a website page activates its source, so a deleted page input and the revised document land in one commit to make the one private revision the saved-record test reads.
page initwrapped every package sheet in a generated@scope (<package tags>) to (<foreign widgets>), rooted at:host(...)in shadow trees, so authors wrote:scopefor "my widget" and Leaf kept a package's rules off widgets nested inside its own. That generated CSS is what Firefox mis-evaluated in #4295, and it guarded cases nothing exercised: every class the bundled packages name is already package-prefixed.Leaf now places each sheet in its cascade tier and rewrites none of its rules. Package sheets name their widgets:
lf-tabs .lf-tabstripin the document,:host(lf-diff.lf-rendered) .xin a shadow tree. A codemod made the ~570:scopeedits; an authored@scope (html[data-lf-interactive] :scope)keeps its native meaning, now rooted at the widget it styles. widget-shadow.css still reaches both trees. The theme-shadow.css role goes: a theme reaches shadow trees through the custom properties they inherit. The diff's palette and geometry no longer load twice, since the document rule already sets them on the host.Behavior: a package's rules now reach a foreign widget nested inside its widgets, which no bundled rule does. Measured by reading 42 computed properties on every element, shadow trees included, across 17 examples in Chromium and 7 in Firefox, main against this change, two examples differ, both toward what their package declares. A visual review's capture shot now takes the
margin: 0its package declares (it had kept 10px from the default package through scope proximity). A deck's open card now drops its first and last child's outer margins, as the deck's rules say; the generated limit had stopped those rules at the card, anlf-askfrom another package. The diagram's negative end margin lost specificity to the layer's trim of a frame's last margin and now names:last-childto keep it.Tests: the contract test for the generated boundary goes with it; the shadow confinement test now writes
:host(lf-own-tree) spanand still runs in every engine; the theme-shadow test goes. No protocol bump: a page vendored earlier keeps its composed sheets, which the runtime doesn't read differently.Deleting
page-sheets.js, the runtime rewriting of page CSS, follows in its own PR.