Skip to content

Descendant combinator is incorrectly applied to elements inside a shadow tree #40896

@longvatrong111

Description

@longvatrong111

Describe the bug:
Descendant combinator shouldn't apply to an element if the element is inside a shadow tree and the matching ancestor is outside the shadow tree.

Servo can mainly handle this case, but fail if bring <style> into the shadow tree.

To Reproduce:
Test case:

<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>Shadow DOM Style Test</title>
</head>
<body>
    <div class="parent">
        <common-cart id="hostElement"></common-cart>
    </div>

    <script>
        const hostElement = document.getElementById('hostElement');
        const shadowRoot = hostElement.attachShadow({mode: 'open'});

        shadowRoot.innerHTML = `
            <div class="child">
                <style>
                  .parent .child {
                      border: 5px solid red;
                      background-color: yellow;
                  }
                </style>
                This element is inside the Shadow DOM. <br>
                It should NOT have a red border and yellow background from descendant combinator style.
            </div>
        `;
    </script>
</body>
</html>

Chromium:
Image

Servo:
Image

Metadata

Metadata

Labels

A-content/cssInteracting with CSS from web content (parsing, serializing, introspection)C-has-manual-testcase

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions