Bug 276454

Summary: Style doesn't update on :scope when an element is no longer a candidate for a CSS Scope rule
Product: WebKit Reporter: Zacky Ma <zacky>
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: koivisto, m_dubet, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 17   
Hardware: All   
OS: All   

Zacky Ma
Reported 2024-07-10 16:24:47 PDT
When an element is changed and should no longer be selected by a scope rule, the styles defined in `:scope` persists. For example, given the CSS code: ``` body { color: black; } @scope (.foo) { :scope { color: red; } :scope::after { content: ' more text'; } span { color: green; } } ``` and the HTML code: ``` <body> <p class="foo">Some <span>text</span></p> </body> ``` When `foo` class is removed from `<p>`, the text color in `<p>` remains as red, instead of falling back to be the body color (black); "more text" remains instead of being removed. But the text color in `<span>` is correctly falling back to its parent's color, which is red. Testing Codepen: https://codepen.io/marchbox/pen/JjQovBp
Attachments
Zacky Ma
Comment 1 2024-07-10 16:26:01 PDT
Should've also mentioned, forcing the element to be repainted, e.g. setting `<p>` with `visibility: hidden` then reset `visibility` does correct the styles.
Radar WebKit Bug Importer
Comment 2 2024-07-17 16:31:24 PDT
Matthieu Dubet
Comment 3 2025-08-06 15:40:57 PDT
*** This bug has been marked as a duplicate of bug 279225 ***
Note You need to log in before you can comment on or make changes to this bug.