w3c / w3c/csswg-drafts

[css-view-transitions] Tree scoping: Shadow DOM's view-transition-name property breaks global property

Open
#11,273 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

css-view-transitions-1
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

Here's a tree scoping issue related to #10145 and #10529. This might be intended behavior, but I wanted to double-check, because it's pretty counterintuitive and might affect extensibility.

Say I have this in my global stylesheet:

<style>
  ::part(foo) {
    view-transition-name: foo;
  }
</style>
<my-element></my-element>

and then inside my-element's shadow DOM, I have this:

@customElement("my-element")
export class MyElement extends LitElement {
  render() {
    return html`<div part="foo"></div>`;
  }

  static styles = css`
    div {
      /* This causes the global view-transition-name to have no effect. */
      view-transition-name: foo !important;
    }
  `;
}

In Chrome (stable + Canary), the view-transition-name: foo !important; property inside MyElement causes the global view-transition-name: foo; property to stop having any effect. As a result, the div ends up with no view transition name at all.

Most likely this behavior is correct, and it's just how properties on parts must behave.

That said, I found it pretty counterintuitive, and it seems to me that it breaks encapsulation somewhat. I'm also worried that this behavior might cause extensibility issues down the line, if we want to be able to have the shadow DOM participate in view transitions in a future version of the spec. So I just wanted to raise this so the spec authors can double-check that this is the intended behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the global ::part(foo) rule and the shadow-DOM div example in the issue, then compare the observed view-transition-name behavior with the tree-scoping discussion in issues #10145 and #10529. Done means determining whether the interaction is intended and recording the clarified behavior or required spec change.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.