Closed Bug 1912996 Opened 2 months ago Closed 2 months ago

Editing declaration in stylesheet layer import does not work and might cause blank rules view

Categories

(DevTools :: Inspector: Rules, defect, P2)

defect

Tracking

(firefox131 verified, firefox132 verified)

VERIFIED FIXED
131 Branch
Tracking Status
firefox131 --- verified
firefox132 --- verified

People

(Reporter: nchevobbe, Assigned: emilio)

References

Details

Attachments

(1 file)

  1. Go to https://rqrauhvmra.com/ratata/examples/ratata.html
  2. Open the inspector
  3. Select the h2 element
  4. Change the font-size value to 80px
  5. Now select the h1 element

-> blank rules view (and at step 4, the font-size isn't updated)


There's an error in the Browser Console:

Error while calling actor 'pagestyle's method 'getApplied'" "can't access property \"parsingMode\", sheet is null
resource://devtools/shared/inspector/css-logic.js:139

I reproduce the issue in Firefox 97, which was when @layer support was added

Reduced STR:

  1. Go to https://ffx-devtools-layer-inspector-issue.glitch.me/
  2. Inspect the h1 element
  3. Update the font-size to 80px

-> change isn't applied on the page


The CSS is pretty simple:

style.css:

@layer content;
@import url('./_imported.css') layer(content);

_imported.css

h1 {
  font-size: 40px;
}

Note that if in style.css we remove the @layer rule, we don't suffer from this issue. The rule on the h2 element in the example can be edited fine

fine.css:

@import url('./_imported_fine.css') layer(content);

_imported_fine.css

h2 {
  font-size: 20px;
}

From the DevTools side, we do change the stylesheet text fine, and then call InspectorUtils.parseStyleSheet with the stylesheet.

https://searchfox.org/mozilla-central/rev/2455e4d6388cbdeadb44b9633b971a65a98b504c/devtools/server/actors/utils/stylesheets-manager.js#445-446

const styleSheet = this.#styleSheetMap.get(resourceId);
InspectorUtils.parseStyleSheet(styleSheet, text);

I tried to create a failing InspectorUtils.parseStyleSheet test but I couldn't I guess something different in chrome mochitest? Or the bug comes from a different place.


Emilio, would you have an idea of what's happening here?

Summary: Blank rules view after editing declaration value → Editing declaration in stylesheet layer import does not work and might cause blank rules view
Flags: needinfo?(emilio)

This goes back to bug 1372041 at least...

Flags: needinfo?(emilio)

We've never passed it down even though it was clearly the intention.

This made the invalidation code think the stylesheet was already
detached.

Assignee: nobody → emilio
Status: NEW → ASSIGNED

How hard would it be for you to write a test for it? I tried something like this, but it doesn't repro the issue, it's likely not easy to do a web-observable test-case for this:

<!DOCTYPE html>
<style>@import url("data:text/css,:root{background-color:green}");</style>
<style>@charset "utf-8"; @import url("data:text/css,:root{background-color:green}");</style>
<script>
console.log(document.styleSheets[0].cssRules[0].styleSheet.cssRules[0]);
console.log(document.styleSheets[1].cssRules[0].styleSheet.cssRules[0]);
console.log(document.styleSheets[0].cssRules[0].styleSheet.parentStyleSheet);
console.log(document.styleSheets[1].cssRules[0].styleSheet.parentStyleSheet);
</script>
Flags: needinfo?(nchevobbe)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/9c5849135fa9 Make sure to honor the sheet clone parent. r=firefox-style-system-reviewers,zrhoffman

Sorry, the patch was already queued to land when I found this, but I get an assertion failure on exit.

[1644085] Assertion failure: mParentSheet->ChildSheets().Contains(this), at /home/user/hg.mozilla.org/gecko-dev/layout/style/StyleSheet.cpp:913
Flags: needinfo?(nchevobbe) → needinfo?(emilio)
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 131 Branch
Regressions: 1914449

Opened bug 1914449 for the assertion failure and restoring the ni? for test coverage from bug 1912996 comment 5.

Flags: needinfo?(nchevobbe)

Cancelling the duplicate ni? because it is covered by the ni? in bug 1914449. :)

Flags: needinfo?(emilio)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #5)

How hard would it be for you to write a test for it? I tried something like this, but it doesn't repro the issue, it's likely not easy to do a web-observable test-case for this:

<!DOCTYPE html>
<style>@import url("data:text/css,:root{background-color:green}");</style>
<style>@charset "utf-8"; @import url("data:text/css,:root{background-color:green}");</style>
<script>
console.log(document.styleSheets[0].cssRules[0].styleSheet.cssRules[0]);
console.log(document.styleSheets[1].cssRules[0].styleSheet.cssRules[0]);
console.log(document.styleSheets[0].cssRules[0].styleSheet.parentStyleSheet);
console.log(document.styleSheets[1].cssRules[0].styleSheet.parentStyleSheet);
</script>

Sorry I was out last week, thanks a lot for the fix! I'll write an inspector test for this

Flags: needinfo?(nchevobbe)
QA Whiteboard: [qa-131b-p2]

Reproducible on a 2024-08-13 Nightly build on Windows 10 using the STR from Comment 2.
Verified as fixed on Firefox 131.0b5 and Firefox Nightly 132.0a1 on Windows 10, Ubuntu 22, macOS 14.

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-131b-p2]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: