Fix panic when a selector deposits parent flags on the Document - #648
Open
latentharbor wants to merge 1 commit into
Open
Fix panic when a selector deposits parent flags on the Document#648latentharbor wants to merge 1 commit into
latentharbor wants to merge 1 commit into
Conversation
`Node::selector_flags()` is generated by `element_accessors!`, so it
exists only on Element and AnonymousBlock nodes. Stylo's
`apply_selector_flags` deposits the `for_parent()` half of a match on the
raw parent node:
if let Some(parent) = self.parent_node() {
parent.selector_flags().set(parent.selector_flags().get() | parent_flags);
}
For the root `<html>` that parent is the Document node, where the field
does not exist, and the accessor panics with
`selector_flags` is not available on this node kind
`for_parent()` covers `:first-child`, `:last-child`, `:only-child`,
`:nth-child()`, `:nth-last-child()`, `~` and `+`, so the minimal
reproduction needs no script, no network and no shadow DOM:
<style>*:first-child { color: red }</style><p>hello</p>
`universal_accessors!` already carries a Document arm for `element_state`
and `snapshot_handled` for exactly this reason; `selector_flags` was
missed. This moves it to the same macro.
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.
Node::selector_flags()is generated byelement_accessors!, so it exists only on Element and AnonymousBlock nodes. Stylo'sapply_selector_flagsdeposits thefor_parent()half of a match on the raw parent node:For the root
<html>that parent is the Document node, where the field does not exist, and the accessor panics with ```selector_flagsis not available on this node kind.for_parent()covers:first-child,:last-child,:only-child,:nth-child(),:nth-last-child(),~and+, so the minimal reproduction needs no script, no network and no shadow DOM:universal_accessors!already carries a Document arm forelement_stateandsnapshot_handledfor exactly this reason;selector_flagswas missed. This moves it to the same macro.Found while running the Web Platform Tests against blitz-dom in OpenKitesurf, where it was breaking real pages — react.dev among them.