Closed Bug 1877025 Opened 5 months ago Closed 4 months ago

Declarative Shadow DOM: this.attachInternals().shadowRoot is always null

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 124
defect

Tracking

()

RESOLVED FIXED
124 Branch
Tracking Status
firefox124 --- fixed

People

(Reporter: constantin.schellhammer, Assigned: avandolder)

Details

Attachments

(2 files)

Steps to reproduce:

  1. add declarative shadow dom custom element with template.shadowrootmode = "closed" or "open"
  2. register custom element: constructor: this.attachInternals().shadowRoot

Actual results:

this.attachInternals().shadowRoot is null

Expected results:

this.attachInternals().shadowRoot should not be null for both "open" and "closed" shadow roots (Chrome/Edge behave as expected). For "closed" shadow roots this.shadowRoot is null, too. So this.attachInternals().shadowRoot is the only way to make a "closed" shadow root interactive.

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

We might not be setting the available to element internals to true (https://html.spec.whatwg.org/#parsing-main-inhead:available-to-element-internals)?

Severity: -- → S3
Flags: needinfo?(avandolder)
Attached file Testcase

Reporter: thanks for reporting, it would also really help if you attach a testcase instead of describing the problem in prose.

Status: UNCONFIRMED → NEW
Ever confirmed: true

testcase:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bug 1877025</title>
    <script type="module">
        customElements.define("custom-element",class extends HTMLElement {
            #internals;
            constructor() {
                super();
                this.#internals = this.attachInternals();
                console.assert(this.#internals.shadowRoot!==null);
            }
        })
    </script>
</head>
<body>
    <custom-element>
        <template shadowrootmode="closed">
            Bug 1877025
        </template>
    </custom-element>
</body>
</html>

(In reply to Peter Van der Beken [:peterv] from comment #2)

We might not be setting the available to element internals to true (https://html.spec.whatwg.org/#parsing-main-inhead:available-to-element-internals)?

Ah, since we create the shadow root from the parser, I don't think the element would have a CustomElementData yet, which we check before setting available to element internals.

Flags: needinfo?(avandolder)
Assignee: nobody → avandolder
Status: NEW → ASSIGNED

Do we need this on beta?

Pushed by avandolder@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b34477dd4ac2
Make declarative shadow roots of custom elements available to element internals. r=peterv,dom-core
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/44419 for changes under testing/web-platform/tests

Backed out for lint failure on shadow-dom/declarative/declarative-shadow-dom-available-to-element-internals.html

Backout link: https://hg.mozilla.org/integration/autoland/rev/6ac6ad4ee06483569b7ac1e6789796a51414f802
Log link: https://treeherder.mozilla.org/logviewer?job_id=446171810&repo=autoland&lineNumber=69

Flags: needinfo?(avandolder)
Upstream PR was closed without merging
Pushed by avandolder@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/40bac1b10006
Make declarative shadow roots of custom elements available to element internals. r=peterv,dom-core
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 124 Branch
Upstream PR merged by moz-wptsync-bot
Flags: needinfo?(avandolder)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: