[Webkit-unassigned] [Bug 141450] Web Inspector: Better support for CSSOM StyleSheet mutations (insertRule/deleteRule)

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Mar 19 11:30:30 PDT 2024


Qianlang Chen <qianlangchen at apple.com> changed:

           What    |Removed                     |Added
                 CC|                            |qianlangchen at apple.com

--- Comment #2 from Qianlang Chen <qianlangchen at apple.com> ---
As noted, this behavior is introduced by fixing this bug: https://webkit.org/b/141451 (Safari crashes when inspecting an element with a style rule whose parent style sheet has been mutated by JavaScript)

However, I cannot reproduce the crash after taking out the above fix and allowing such rules to be edited anyway. What I find instead is that editing a rule suddenly removes all rules inserted by JavaScript. This is because we currently handle style edits by clearing ALL existing rules, replacing the text in the rule's parent style sheet, and re-parsing the entire style sheet. When re-parsing, JavaScripted-inserted rules do not have text, so they're missing during the re-parse. (See https://github.com/patrickangle/WebKit/blob/b1dd655b710e45f59c91ef803255a8dbc4fc94e1/Source/WebCore/inspector/InspectorStyleSheet.cpp#L1506-L1509, which was introduced by this patch: https://github.com/WebKit/WebKit/pull/9499)


To resolve this, I came up with two strategies:

* Strategy A: When editing a style, instead of re-parsing the style sheet's modified text, make use of CSSOM and call CSSStyleDeclaration::setCssText() with the new text. The replacement and canonicalization of the new style sheet's text are still done to support viewing the updated source code. To accommodate undoing, record the style sheet's text as well as the old CSSStyleDeclaration::cssText().
    - I have this fix in a draft PR here: https://github.com/WebKit/WebKit/pull/25924

* Strategy B: Keep the re-parsing. When using JavaScript to insert a rule, generate its text and insert it into the style sheet's source text too.

Both of these strategies rely on having addressed this bug first: https://webkit.org/b/141450 (A ParsedStyleSheet::m_sourceData gets misaligned with the CSSRules after style sheet is mutated). Otherwise, the inspector's frontend gets the wrong text for all the CSS rules residing after the JavaScript-insertion point in a style sheet.

You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20240319/61763ff9/attachment.htm>

More information about the webkit-unassigned mailing list