Stylesheet change adds new stylesheet in style editor
Categories
(DevTools :: Style Editor, defect)
Tracking
(Not tracked)
People
(Reporter: nchevobbe, Assigned: nchevobbe)
References
Details
Steps to reproduce
- Go to
data:text/html,<meta charset=utf8><style></style><button>Update stylesheet</button><script>document.addEventListener("click", () => {%20 document.querySelector("style").textContent = 'body::after{ content: "' + Date.now() + '" }'; })</script>
- Open Style Editor
- Click on the "Update stylesheet" buttons multiple time
Expected results
There's still only 1 stylesheet displayed in the list
Actual results
Every click on the button added a stylesheet in the list
Assignee | ||
Comment 1•1 year ago
|
||
In this case, we get a StyleSheetApplicableStateChanged
event, which ends up calling _registerStyleSheet
_onApplicableStateChanged({ applicable, stylesheet: styleSheet }) {
...
this._registerStyleSheet(styleSheet);
...
_registerStyleSheet(styleSheet) {
const existingResourceId = this._findStyleSheetResourceId(styleSheet);
// If the stylesheet is already registered, there's no need to notify about it again.
if (existingResourceId) {
return existingResourceId;
}
but here we don't find the existing styleSheet, and so we go on as if it was a new stylesheet.
_findStyleSheetResourceId(styleSheet) {
for (const [
resourceId,
existingStyleSheet,
] of this._styleSheetMap.entries()) {
if (styleSheet === existingStyleSheet) {
return resourceId;
}
}
return null;
}
this._styleSheetMap
does have a stylesheet at this point, but this doesn't match the one we get from the event.
The stylesheet we get from the event does match the document stylesheet (this._targetActor.window.document.styleSheets[0]
), so somehow, the instance that we store then gets replaced.
And actually that's something we can observed on a regular webpage, changing the textContent
(or appending a new text node) of a <style>
node will end up creating a new stylesheet, which makes sense.
The fact that we see multiple items in the style editor looks like Bug 1771113, so that might be a good moment to handle this
Assignee | ||
Updated•1 year ago
|
Description
•