"Add new rule" button stops working when style node is deleted or moved
Categories
(DevTools :: Inspector: Rules, defect, P3)
Tracking
(firefox97 verified)
Tracking | Status | |
---|---|---|
firefox97 | --- | verified |
People
(Reporter: dev, Assigned: colin.cazabet, Mentored)
Details
Attachments
(2 files)
5.53 MB,
video/quicktime
|
Details | |
Bug 1736412 - [devtools] Fix 'Add new rule' button when style node is deleted or moved. r=jdescottes
48 bytes,
text/x-phabricator-request
|
Details | Review |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36
Steps to reproduce:
-
Open any page in Firefox. For example, the following file content can be used for reproducing:
<html>
<body>
<div>This is some placeholder content.</div>
</body>
</html> -
Open the dev tools and select an element in the inspector.
-
In the rules view, press the "Add new rule" button. A new (empty) style declaration is added in the rules view. Also, an empty <style> element is added to the end of the DOM.
-
Delete this new style element (or move it to a different place in the DOM using drag-and-drop).
-
Press the "Add new rule" button again.
Actual results:
When pressing the "Add new rule" button at step 5, nothing happens (even when pressing it repeatedly).
Expected results:
The same as what happens when the button is pressed in step 3:
A new (empty) style declaration should be added, and a new empty <style> element should be added to the end of the DOM.
Comment 1•3 years ago
|
||
Thanks for the report, I can confirm the bug happens with the current Nightly, and is probably not a recent regression.
Setting P3/S3 because STRs are a bit complex, but it would really be nice to fix, especially considering there is 0 user feedback.
Updated•3 years ago
|
Comment 2•3 years ago
|
||
Reproduced in ESR 78
Comment 3•3 years ago
|
||
The issue comes from the PageStyleActor. This DevTools actor holds a WeakMap of all stylesheets added for the "add new rule" feature. This WeakMap is keyed by document (we add one stylesheet per document). But when we delete the stylesheet, nothing will cleanup the WeakMap.
Depending whether we use the watcher or not, this WeakMap is queried in different spots:
- without watcher support: https://searchfox.org/mozilla-central/rev/489e82dcc1e5afbe691ff3b1c982382914637e38/devtools/server/actors/page-style.js#1127-1137
- with watcher support https://searchfox.org/mozilla-central/rev/489e82dcc1e5afbe691ff3b1c982382914637e38/devtools/server/actors/page-style.js#1164-1168
Instead of only querying the WeakMap in those spots, we could also check if the stylesheet is still in the document, by calling isConnected
. I don't think anything else would be needed here.
We will have to add a test, which is probably going to make this a bit too complicated for a good-first-bug. We could start with something similar to one of the browser_rules_add-rule* tests. The steps should more or less be:
- use add new rule and check the rule is applied
- use SpecialPowers.spawn to delete the style element from the content page
- use add new rule again and check the rule is applied
Setting myself as mentor, but note I will be away between Oct 25th and Nov 2nd
Assignee | ||
Comment 4•3 years ago
|
||
Hello,
I'm willing to work on this bug if nobody is assigned yet.
Thank you,
Colin
Comment 5•3 years ago
|
||
Hello Colin, thanks for offering help :)
The bug is now yours. Let me know if you have any question
Assignee | ||
Comment 6•3 years ago
|
||
Hello Julian,
I fixed the problem but I have some questions regarding the testing part.
I never used "SpecialPowers" and I cannot find the documentation on it, could you try to explain me what SpecialPowers.spawn does ?
Thank you
Assignee | ||
Comment 7•3 years ago
|
||
Assignee | ||
Comment 8•3 years ago
|
||
Hello Julian,
I found how to use "SpecialPowers" by looking on searchfox, I think I fixed the bug. I also wrote some tests
Thank you
Comment 9•3 years ago
|
||
Hi Colin, sorry I missed your questions :/
Glad you managed to use SpecialPowers!
For info you can use the "Request information from" checkbox below to make sure we receive a notification for your question.
Comment 10•3 years ago
|
||
Comment 11•3 years ago
|
||
bugherder |
Updated•3 years ago
|
Comment 12•3 years ago
|
||
I was able to reproduce the issue on Win10x64 using build 95.0a1(20211018214442) and steps from description.
Verified as fixed on Win10/Mac 10.13/Ubuntu 20.4 using builds 98.0a1(20220131094559) and 97.0b9 (20220127193706).
Description
•