Closed Bug 1833679 Opened 2 years ago Closed 1 year ago

Generate DevTools warning for Unconstrained `:has()` selectors

Categories

(Core :: CSS Parsing and Computation, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
121 Branch
Tracking Status
firefox121 --- fixed

People

(Reporter: dshin, Assigned: dshin)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Unconstrained :has(...) (Unlike say div:has(...)) selectors require us to try matching all elements, and disable style sharing. This has pretty bad perf implications, so we should warn the authors.

See Also: → 1822177
Severity: -- → S3
Assignee: nobody → dshin

I'm wondering if this should be a CSS warning (i.e. the user needs to enable the CSS filter on the console to see it)
In such case, it might be lost in a see of other warnings
It might be more impactful to show an icon + tooltip in the rule view, where people writing CSS might spend their time in

It makes me wonder if there are other selectors that could have similar impact on performance

(In reply to Nicolas Chevobbe [:nchevobbe] from comment #2)

In such case, it might be lost in a see of other warnings

Unfortunately, yeah...

It might be more impactful to show an icon + tooltip in the rule view, where people writing CSS might spend their time in

Hm - would it be something like a built-in CSS linter? That'd be useful.

It makes me wonder if there are other selectors that could have similar impact on performance

At least I'd say :has has the largest impact by far.

(In reply to David Shin[:dshin] from comment #3)

It might be more impactful to show an icon + tooltip in the rule view, where people writing CSS might spend their time in

Hm - would it be something like a built-in CSS linter? That'd be useful.

yes I think it would be nice. I'm currently thinking about this piece of UI in DevTools (with nesting on its way, it might be nice to have a way to display desugared selector and specificity), and so it's a good opportunity to think about this "slow" warning.

Is there a way we could expose a Chrome-only boolean property (e.g. slowSelector) on the CSSRule so DevTools could identify those?
It might even be better to have 1. the selector indexes of those slow selector and 2. some kind of string that would link to a localized error message that DevTools could retrieve

David, what do you think of what I suggest in Comment 4 ?
Would that be hard to implement?
Also, could you provide a test page where :has is slow so we can use it while prototyping this?

thanks

Flags: needinfo?(dshin)

This is doable, and I think it makes a lot of sense. Just need to get the interface right.

I have gotten started on prototyping this, but my focus is on bug 1792501 at the moment.
There are many examples where :has would become slow, but .anchor:has(*) (Which would have to invalidate every time anything inserts/removes in DOM) is a good example. I'll try to assemble a document.

Flags: needinfo?(dshin)

(In reply to Nicolas Chevobbe [:nchevobbe] from comment #4)

Is there a way we could expose a Chrome-only boolean property (e.g. slowSelector) on the CSSRule so DevTools could identify those?
It might even be better to have 1. the selector indexes of those slow selector and 2. some kind of string that would link to a localized error message that DevTools could retrieve

Alternatively, we could have a InspectorUtils method that we would call to get warning messages about a selector text (or the rule directly, depending what would be the most efficient)
So for example InspectorUtils.getSelectorsWarning(selectorText | cssRule) would return an array of objects of the following form:

{
  selectorIndex: 0,
  warningL10N: "unconstrainedHas"
  type: "slow" // not sure about this, but we might get other kind of warnings in the future ? 
}

I feel like this would be simpler to implement than what I suggested in Comment 4 (and wouldn't have performance impact when DevTools is not open).
Let me know what you think David, it would be nice to have this soon since :has is already enabled in Nightly

Flags: needinfo?(dshin)

(In reply to Nicolas Chevobbe [:nchevobbe] from comment #7)

(In reply to Nicolas Chevobbe [:nchevobbe] from comment #4)

Is there a way we could expose a Chrome-only boolean property (e.g. slowSelector) on the CSSRule so DevTools could identify those?
It might even be better to have 1. the selector indexes of those slow selector and 2. some kind of string that would link to a localized error message that DevTools could retrieve

Alternatively, we could have a InspectorUtils method that we would call to get warning messages about a selector text (or the rule directly, depending what would be the most efficient)
So for example InspectorUtils.getSelectorsWarning(selectorText | cssRule) would return an array of objects of the following form:

{
  selectorIndex: 0,
  warningL10N: "unconstrainedHas"
  type: "slow" // not sure about this, but we might get other kind of warnings in the future ? 
}

I feel like this would be simpler to implement than what I suggested in Comment 4 (and wouldn't have performance impact when DevTools is not open).
Let me know what you think David, it would be nice to have this soon since :has is already enabled in Nightly

(Tying up loose ends on :has, but getting to this very soon)

Ah, I like that approach, actually - seems to be a more "right" place.
As per bug 1833679 comment 1, we'd have "neverMatches" type as well.

Flags: needinfo?(dshin)
Attachment #9359153 - Attachment description: Bug 1833679 - DevTools warnings infrastrcucture. r=nchevobbe,emilio → Bug 1833679 - DevTools warnings infrastrcucture for unconstrained relative selectors. r=nchevobbe,emilio
Attachment #9359153 - Attachment description: Bug 1833679 - DevTools warnings infrastrcucture for unconstrained relative selectors. r=nchevobbe,emilio → Bug 1833679 - DevTools warnings infrastructure for unconstrained relative selectors. r=nchevobbe,emilio
Attachment #9359153 - Attachment description: Bug 1833679 - DevTools warnings infrastructure for unconstrained relative selectors. r=nchevobbe,emilio → Bug 1833679 - DevTools warnings infrastrcucture. r=nchevobbe,emilio
Attachment #9359153 - Attachment description: Bug 1833679 - DevTools warnings infrastrcucture. r=nchevobbe,emilio → Bug 1833679 - DevTools warnings infrastructure. r=nchevobbe,emilio
Attachment #9359153 - Attachment description: Bug 1833679 - DevTools warnings infrastructure. r=nchevobbe,emilio → Bug 1833679 - DevTools warnings infrastrcucture. r=nchevobbe,emilio
Blocks: 1860634
Attachment #9359153 - Attachment description: Bug 1833679 - DevTools warnings infrastrcucture. r=nchevobbe,emilio → Bug 1833679 - DevTools warnings infrastructure. r=nchevobbe,emilio
Pushed by dshin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b32fede7af39 DevTools warnings infrastructure. r=nchevobbe,emilio
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 121 Branch
Regressions: 1862900
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: