Skip to content

Don't panic when matching pseudo-element selectors against unstyled elements - #652

Open
nicoburns wants to merge 1 commit into
mainfrom
devin/1786204525-nesting-pseudo-match
Open

Don't panic when matching pseudo-element selectors against unstyled elements#652
nicoburns wants to merge 1 commit into
mainfrom
devin/1786204525-nesting-pseudo-match

Conversation

@nicoburns

@nicoburns nicoburns commented Aug 8, 2026

Copy link
Copy Markdown
Member

Summary

Fixes CRASHes in css/css-nesting/nesting-basic.html and css/css-nesting/contextually-invalid-selectors-003.html (2 → 0 crashes; both now PASS).

Nested rules under a pseudo-element rule (e.g. .test::before { & { ... } }) cause stylo to match a ::before selector component against regular elements during the initial style traversal. Blitz's TElement::match_pseudo_element called el.styles.primary() (which unwrap()s) on the candidate element, but during initial traversal an element's ElementData exists before its primary style has been computed, so this panicked with called Option::unwrap() on a None value at stylo data.rs:187.

Fix in match_pseudo_element:

- el.styles.primary().pseudo().or(...)
+ el.styles.get_primary().and_then(|s| s.pseudo()).or(...)

Treating "no primary style yet" as "no pseudo-element identity" is correct: only Blitz's synthesized pseudo-element/anonymous-box nodes carry a pseudo, and those always have styles by the time they are matched (the AnonymousBlock fallback is unaffected).

Not a stylo bug: the unwrap is in stylo convenience API; the root cause was Blitz assuming primary styles always exist during selector matching.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/a8bd4846bf354f33a6037fffaca1f583
Requested by: @nicoburns

WPT results

2 newly passing, 0 newly failing (net +2).

Full diff (2 changed tests)
+ Crash => Pass css/css-nesting/contextually-invalid-selectors-003.html
+ Crash => Pass css/css-nesting/nesting-basic.html

Generated by the WPT workflow.

@nicoburns nicoburns self-assigned this Aug 8, 2026
@staging-devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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