Closed Bug 1946442 Opened 2 months ago Closed 1 month ago

Adding declaration in Rules view adds it after any nested declaration

Categories

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

defect

Tracking

(firefox137 verified, firefox138 verified)

VERIFIED FIXED
137 Branch
Tracking Status
firefox137 --- verified
firefox138 --- verified

People

(Reporter: nchevobbe, Assigned: nchevobbe)

References

Details

Attachments

(2 files)

Steps to reproduce

  1. Navigate to data:text/html,<meta charset=utf8><style>body { color: red; &:where(*) { color: blue; } }</style>Hello
  2. Open the inspector
  3. In the Rules view, add a color: gold declaration in the body rule, below color: red

Expected results

The text on the page stays blue as there's another (nested) rule declared later

Actual results

The text on the page turns gold.
If we look at the styleeditor, we can see that the declaration is added after the nested declaration

body {
  color: red;
  &:where(*) {
    color: blue;
  }
  color: gold;
}

This is not what's expected, we should get

body {
  color: red;
  color: gold;
  &:where(*) {
    color: blue;
  }
}

as a result, this creates another rule, so when the rule is refreshed you'll see the new declaration in two different rules:

body {
  {
    color: gold;
  }
}
body {
  &:where(*) {
    color: blue;
  }
}
body {
  color: red;
  color: gold;
}

note that this could have a similar cause than Bug 1946439, and both bugs might be fixed with a single patch

Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED

Create a dummy rule with the content of the rule being modified so we can
check if it has a nested rule. In such case, we can then get the location
of the nested rule so we can insert the added text in the correct position.

A few unit test cases are added to make sure the RuleRewriter does handle
nested rules properly.

Severity: -- → S3
Priority: -- → P2
Pushed by nchevobbe@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e43f18d07ffa [devtools] Turn RuleRewriter into a proper ES6 class. r=devtools-reviewers,bomsy. https://hg.mozilla.org/integration/autoland/rev/850b58556292 [devtools] Fix RuleRewriter when dealing with rules containing nested rules. r=devtools-reviewers,jdescottes.
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 137 Branch

Issue is reproducible on a 2025-02-06 Firefox Nightly build on Windows 10.
Verified as fixed on Firefox Nightly 138.0a1 and Firefox 137.0b2 on Windows 10, Ubuntu 22, macOS 14.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
Regressions: 1954704
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: