Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: a529eb4679cc0ebd4529be41d0472814aa0cb7ab
https://github.com/WebKit/WebKit/commit/a529eb4679cc0ebd4529be41d0472814aa0cb7ab
Author: Ahmad Saleem <[email protected]>
Date: 2026-10-14 (Wed, 14 Oct 2026)
Changed paths:
A
LayoutTests/imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-replaceSync-detached-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-replaceSync-detached.html
M Source/WebCore/css/CSSStyleSheet.cpp
Log Message:
-----------
CSSStyleSheet.replaceSync() on a detached constructed stylesheet appends
rules instead of replacing them, and can corrupt other sheets sharing the
cached contents
https://bugs.webkit.org/show_bug.cgi?id=327011
rdar://189634428
Reviewed by Antti Koivisto.
This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.
replaceSync() [1] must replace all of the stylesheet's rules with the
result of parsing the given text.
When a constructed stylesheet is detached and has no CSSOM rule
wrappers, replaceSync() looks the text up in StyleSheetContentsCache.
On a cache miss it parsed the text into the sheet's existing
StyleSheetContents without clearing it first, so the new rules were
appended to the old ones:
sheet.replaceSync(".a {} .b {}");
sheet.replaceSync(".c {} .d {} .e {}");
sheet.cssRules.length; // 5, should be 3
The existing contents may also be shared through the cache: a cache
hit points the sheet at the cached StyleSheetContents. A later cache
miss on that sheet then parsed into the shared object, changing every
other sheet created from the same text, as well as the cache entry
for that text:
first.replaceSync(".a {}");
second.replaceSync(".a {}"); // Cache hit, shares first's contents.
second.replaceSync(".b {}"); // Appended into the shared contents.
first.cssRules; // [.a, .b], should be [.a]
On a cache miss, parse into a new StyleSheetContents created with the
same parser context, and swap it in the same way the cache-hit path
does, so a cache miss never writes into a shared StyleSheetContents.
[1] https://drafts.csswg.org/cssom/#dom-cssstylesheet-replacesync
Test:
imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-replaceSync-detached.html
*
LayoutTests/imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-replaceSync-detached-expected.txt:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-replaceSync-detached.html:
Added.
* Source/WebCore/css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::replaceSync):
Canonical link: https://commits.webkit.org/323736@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications