Skip to content

Update element adoption logic for scoped registry#1437

Merged
annevk merged 1 commit into
whatwg:mainfrom
ja-y-son:scer-element-adopt
Jul 9, 2026
Merged

Update element adoption logic for scoped registry#1437
annevk merged 1 commit into
whatwg:mainfrom
ja-y-son:scer-element-adopt

Conversation

@ja-y-son

@ja-y-son ja-y-son commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Fixing #1429 to make sure element is getting the correct scoped custom element registry upon adoption.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated

@annevk annevk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. We'll need tests next.

For the tests I'd like us to exercise some of the more complicated scenarios with some nodes having been assigned registries and others not, etc.

Comment thread dom.bs Outdated
@ja-y-son

ja-y-son commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

Just added some tests but I haven't fully verified them yet. Feel free to take a look.

Comment thread dom.bs Outdated
@ja-y-son

ja-y-son commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

@annevk Want to verify that this is the expected behavior from this change on effective gloabl registry. Consider this test case from adoption.window.js

test(t => {
  const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument;
  t.add_cleanup(() => contentDocument.defaultView.frameElement.remove());
  const element = document.createElement('div');
  assert_equals(element.customElementRegistry, customElements);

  const scoped = new CustomElementRegistry();
  const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped });
  contentDocument.body.appendChild(scopedElement);
  assert_equals(scopedElement.customElementRegistry, scoped);
  scopedElement.appendChild(element);
  assert_equals(element.customElementRegistry, contentDocument.customElementRegistry);
}, "Adoption with global registry into a scoped registry");

Given that now we look at the parent's registry's effective global registry, the last assert of the test should probably be

assert_equals(element.customElementRegistry, null);

given that the parent is using a scoped registry.
Is this expected? Or we want it to keep getting global registry for this element? It feels a bit odd that it originally has a global registry but after adoption it goes to null registry. Perhaps we should make sure that non-null registry element shouldn't get null registry after adoption (unless there are no global registry available)?

@annevk

annevk commented Dec 4, 2025

Copy link
Copy Markdown
Member

Yeah, I suppose distinguishing those cases would be better. I doubt anyone is going to run into this in practice, but we might as well make it nice.

Comment thread dom.bs Outdated
@ja-y-son

ja-y-son commented Dec 5, 2025

Copy link
Copy Markdown
Contributor Author

I think I made it unnecessarily complicated in the previous iteration. Given that our main goal is that global registry element shouldn't become null registry during adoption, I think we can simply include this category (global registry) to use document's registry's effective global registry, so it wouldn't be getting null from parent. Does this make sense? Or perhaps I'm missing something here.

@annevk annevk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this works. I'll re-review on Monday to be sure. If @sorvell, @rniwa, and maybe @keithamus could have a look as well that'd be great.

(Checking inclusiveDescendant's custom element registry again bothers me a little bit, but I don't see a good way out of that. I also want to double check the "DocumentFragment but not ShadowRoot" language.)

Comment thread dom.bs Outdated
@ja-y-son

ja-y-son commented Jan 4, 2026

Copy link
Copy Markdown
Contributor Author

@annevk Went through this PR again and I think it still works. Do we want to merge this PR first while wrapping up web-platform-tests/wpt#56423

Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
@annevk

annevk commented Jan 7, 2026

Copy link
Copy Markdown
Member

Also, now that "keep custom element registry null" is part of this PR, it depends on whatwg/html#12000 so we should mention that in the commit message and get that PR finished as well.

@ja-y-son

ja-y-son commented Jan 8, 2026

Copy link
Copy Markdown
Contributor Author

I updated the commit message so it mentions the new concept that will be defined in whatwg/html#12000. I'll prioritize getting this adoption logic PR landed and will for sure get the attribute PR finished next. Let me know if you prefer me to take "keep custom elemetn registry null" idea out of this PR for now; I can also land this PR without the concept and put it together with attribute PR.

@annevk

annevk commented Jan 8, 2026

Copy link
Copy Markdown
Member

Let's keep it out of this PR then.

@annevk
annevk force-pushed the scer-element-adopt branch from 7e87fef to 1e6abda Compare January 13, 2026 10:51
@ja-y-son

Copy link
Copy Markdown
Contributor Author

@annevk Thanks for the review and the nit! I don't seem to have the permission to merge the PR. Mind landing this PR for me?

@annevk

annevk commented Jan 14, 2026

Copy link
Copy Markdown
Member

Ryosuke said he'd make time for the tests this week and I'd like to wait for that as we land tests and specification changes around the same time.

@annevk annevk added the topic: custom elements Relates to custom elements (as defined in DOM and HTML) label Jun 10, 2026
@annevk
annevk force-pushed the scer-element-adopt branch from 1e6abda to d1bdc30 Compare July 3, 2026 09:06
Fixes whatwg#1429 by making sure elements get the correct scoped custom
element registry upon adoption.
@annevk
annevk force-pushed the scer-element-adopt branch from d1bdc30 to e3c3983 Compare July 3, 2026 09:07
annevk added a commit to web-platform-tests/wpt that referenced this pull request Jul 9, 2026
This is for whatwg/dom#1437.

Co-authored-by: Jayson Chen <jaysonchen@microsoft.com>
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
@annevk
annevk merged commit 5796f71 into whatwg:main Jul 9, 2026
2 checks passed
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Jul 12, 2026
… upon adoption, a=testonly

Automatic update from web-platform-tests
Add test cases for null registry element upon adoption

This is for whatwg/dom#1437.

Co-authored-by: Jayson Chen <jaysonchen@microsoft.com>
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
--

wpt-commits: 94069d6fa9641c846ceb7d2a5d69a215274de0d4
wpt-pr: 56423
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: custom elements Relates to custom elements (as defined in DOM and HTML)

Development

Successfully merging this pull request may close these issues.

2 participants