Implement :nth-child(An+B of S) - #800
Open
nicoburns wants to merge 3 commits into
Open
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enables
:nth-child(An+B of S)/:nth-last-child(An+B of S)parsing and adds the embedder-side invalidation it requires. Matching is already generic in stylo/selectors; the missing piece is that a mutation on one child can change which siblings match (their nth-of index changes), which stylo's downward snapshot invalidation can't reach. This mirrors Gecko'sRestyleManager::RestyleSiblingsForNthOf.Depends on (and temporarily rev-pins stylo to) DioxusLabs/stylo#16, which adds a separate
layout.css.nth-child-of.enabledpref (and alayout.css.has-selector.enabledpref for later:has()work). Blitz enables only the nth-of pref. TODO comment notes reverting to crates.io once a stylo release ships the prefs.Invalidation
New
BaseDocument::restyle_siblings_for_nth_of(node_id):HAS_SLOW_SELECTOR_NTH_OF(set by stylo viaapply_selector_flagsduring matching)HAS_SLOW_SELECTOR(:nth-last-child(.. of S)), later siblings only ifHAS_SLOW_SELECTOR_LATER_SIBLINGS(:nth-child(.. of S)), by insertingRestyleHint::restyle_subtree()and marking ancestors dirtyHooked at the two mutation classes that can change
of Smatching:DocumentMutator::{set_attribute, clear_attribute}— gated by newattribute_might_affect_nth_of, which consults the stylist's nth-of dependency maps (might_have_nth_of_{attribute,id,class}_dependency) using both old and new id/class valuesBaseDocument::snapshot_node_and(element state changes, e.g.:checked) — gated byhas_nth_of_state_dependencyAlso fixes
DocumentMutator::remove_nodeto insertrestyle_subtree()on the parent like the other removal paths already do (plain positional:nth-childneeds this too; found via the new insertion/removal test).Tests
packages/blitz-test-harness/tests/nth_child_of.rs: static matching plus dynamic invalidation for sibling class add/remove, id change, arbitrary attribute change,:checkedstate change, insertion/removal, and:nth-last-child(.. of S).Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/65287500bfb04b2589b9fc6a08bc2d14
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/65287500bfb04b2589b9fc6a08bc2d14?variant=devin-insiders
Requested by: @nicoburns
WPT results
36 newly passing, 2 newly failing (net +34).
Full diff (38 changed tests)
Generated by the WPT workflow.