Closed Bug 1604989 Opened 5 years ago Closed 5 years ago

CSS Shadow Parts rules only apply to first of type

Categories

(Core :: CSS Parsing and Computation, defect, P2)

73 Branch
defect

Tracking

()

VERIFIED FIXED
mozilla73
Tracking Status
firefox-esr68 --- unaffected
firefox72 + verified
firefox73 --- verified

People

(Reporter: aomarks, Assigned: emilio)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36

Steps to reproduce:

It seems that in Firefox Nightly 73.0a1 (2019-12-18) with layout.css.shadow-parts.enabled=true, a ::part rule is only applied to elements that are the first of their type within their shadow root. (I might not have fully pinned down the behavior, but this seems to match what I'm seeing).

For example, given the rule:

<style>
::part(redpart) { color: red; }
</style>

Then this part will correctly be red:

<shadow-host>
#shadow-root
<div part="redpart">correctly red</div>

But this one will not be red:

<shadow-host>
#shadow-root
<div></div>
<div part="redpart">incorrectly black</div>

And if I add another node with the same part attribute, but that is a different element, then that new node does match:

<shadow-host>
#shadow-root
<div></div>
<div part="redpart">incorrectly black</div>
<span part="redpart">correctly red</span>

Simple repro: https://jsbin.com/pohakiveqo/1/edit?html,output

More complex repro that also uses exportparts: https://jsbin.com/yuyigopoyo/1/edit?html,output

Note the above two jsbin repros look correct in Chrome.

Firefox Nightly 73.0a1 (2019-12-18) (64-bit)
layout.css.shadow-parts.enabled = true
Linux 5.2.17-1

Actual results:

Only when a part node is the first of its type in its shadow root does it seem to receive style from a ::part rule.

Expected results:

A ::part rule should apply to all nodes in the shadow root of a matching shadow host without regard to sibling structure.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Blocks: shadowdom
Component: DOM: Core & HTML → CSS Parsing and Computation

Could you attach a test-case that reproduces the issue?

Flags: needinfo?(aomarks)

Ah, sorry, missed the jsbin link.

Flags: needinfo?(aomarks)
Attached file Simplified test-case.

The fact that dynamically adding and removing the attribute works makes it sound like somehow we don't set the "has part attr" bit correctly... Weird, will take a look.

Assignee: nobody → emilio
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Priority: -- → P2
Attachment #9118182 - Attachment mime type: text/plain → text/html

Do the same we do for classes for now. We could be more precise and achieve a
bit more sharing with some more effort (left a comment there), but it seems
unlikely to matter in practice (and if we did that, we'd probably want to do the
same for classes).

Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1907a23a8d6e Do not incorrectly share style across elements with different part names. r=nordzilla
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/20972 for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla73
Upstream PR merged by moz-wptsync-bot

It looks like the patch for this bug wasn't included in Firefox 72, which was just released and has layout.css.shadow-parts.enabled true by default. Shadow parts are not very usable with this bug present. Will there be an off-cycle release before 73 that includes this patch?

Comment on attachment 9118200 [details]
Bug 1604989 - Do not incorrectly share style across elements with different part names. r=#style

Beta/Release Uplift Approval Request

  • User impact if declined: New feature shipped in 72 has a hard-to-workaround bug. Sites using it may behave erratically.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: Yes
  • If yes, steps to reproduce: comment 0 / test-case attached to the bug
  • List of other uplifts needed: none
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Share less styles to avoid correctness issues.
  • String changes made/needed: none
Attachment #9118200 - Flags: approval-mozilla-release?
Flags: qe-verify+

Ugh, looks like I forgot to request uplift, sorry for that :(

To be clear (for release managers): Not sure this is dot-release worthy, so feel free to approval-, but then we should probably disable the feature on release or something.

(In reply to Alexander Marks from comment #10)

It looks like the patch for this bug wasn't included in Firefox 72, which was just released and has layout.css.shadow-parts.enabled true by default. Shadow parts are not very usable with this bug present. Will there be an off-cycle release before 73 that includes this patch?

Adding a [part] selector to the shadow root can work as a workaround, fwiw.

QA Whiteboard: [qa-triaged]

Confirmed issue with 72.0 on Windows 10 using the test cases.
Fix verified with 73.0b2 on Windows 10, macOS 10.15, Ubuntu 18.04.

Waiting for the decision regarding the dot-release worthyness with updating the other flags.

With Edge release ::part() support this wednesday, it would be really great if we had it working across three browsers as soon as possible.

Comment on attachment 9118200 [details]
Bug 1604989 - Do not incorrectly share style across elements with different part names. r=#style

fix for css shadow parts (new in 72); approved for 72.0.2

Attachment #9118200 - Flags: approval-mozilla-release? → approval-mozilla-release+

Verified with 72.0.2 - Windows 10, macOS 10.15, Ubuntu 19.04.

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

Attachment

General

Created:
Updated:
Size: