html icon indicating copy to clipboard operation
html copied to clipboard

Window.customElements shouldn't change when initial about:blank is replaced with a loaded page?

Open smaug---- opened this issue 8 months ago • 7 comments

What is the issue with the HTML Standard?

Seems like https://github.com/whatwg/html/pull/10869 changed the behavior, but I think the old behavior was less surprising for window.customElements users.

https://whatpr.org/html/10869/d745538...9ad774d/custom-elements.html#custom-elements-api

A testcase https://mozilla.pettay.fi/moztests/ce_registry.html Gecko and Blink have the old behavior, Webkit the new.

smaug---- avatar Mar 04 '26 16:03 smaug----

This was discussed and intentionally changed to make document.customElementRegistry the source of truth.

annevk avatar Mar 05 '26 06:03 annevk

I don't want to change document.customElementRegistry being the source of truth, but I think the loaded page should inherit registry from initial about:blank. It is, IMO, rather surprising that both documents get their own registries. That breaks window.open() case, if one registers custom element definitions before the page load.

smaug---- avatar Mar 05 '26 10:03 smaug----

@josepharhar

smaug---- avatar Mar 05 '26 15:03 smaug----

I wonder what is going wrong with the existing per-document.html test then by the way: https://wpt.fyi/results/custom-elements/registries

That uses some generic framework that attempts to test this, but I guess it does a poor job at it?

annevk avatar Mar 05 '26 15:03 annevk

Hi, @annevk I'd love to work on this as a contributor.

dataCenter430 avatar Mar 05 '26 23:03 dataCenter430

@ja-y-son

josepharhar avatar Mar 10 '26 15:03 josepharhar

5. I wonder what is going wrong with the existing per-document.html test then by the way: https://wpt.fyi/results/custom-elements/registries That uses some generic framework that attempts to test this, but I guess it does a poor job at it?

Per spec #shared-document-creation-infrastructure step 6 we reuse the inner window when navigating away from initial about:blank. But browsers differentiate between transient/temporary about:blank (window.open(foo).document) and a more permanent / initial navigation to about:blank for which load is fired (w = window.open().document; w.location=foo). I think https://github.com/whatwg/html/issues/3267 is about that. Note that the spec has no concept of an initial navigation to about:blank, https://github.com/whatwg/html/issues/12778.

We also have custom-elements/revamped-scoped-registry/initial-about-blank.tentative.window.js that is supposed to test this but has the same issue.

I'll try to update object-association.js.


Gecko and Blink have the old behavior, Webkit the new.

WebKit also doesn't seem to associate the registry with the document and rather clears it on window reuse. I believe there are more differences between browsers in regard to what things they reset on the window when it's being reused. https://github.com/whatwg/html/issues/3267#issuecomment-2894496042

vinhill avatar Oct 27 '26 16:10 vinhill