Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scoped-custom-element-registry] Improve issues related to formAssociated #581

Merged
merged 8 commits into from
Jun 6, 2024

Conversation

sorvell
Copy link
Collaborator

@sorvell sorvell commented May 6, 2024

Fixes #546, #547, #580, #570, #549.

Note, bulk of changes in this commit.

The setting for a defined class' formAssociated cannot be properly polyfilled per registry. To address this, previously the polyfill always set the stand-in class to be formAssociated == true. However, this caused a series of subtle issues.

Instead, it is now set to whatever the first defined tag name's formAssociated is set. It's also possible to reserve a given name to always be formAssociated by adding it to customElementRegistryPolyfill.formAssociated.add(tagName).

Unconditionally installs polyfill.

Adds registry to ShadowRootInit

Copy link

google-cla bot commented May 6, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@@ -11,12 +11,22 @@
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
if (!ShadowRoot.prototype.createElement) {
if (!(ShadowRoot.prototype.createElement && ShadowRoot.prototype.importNode)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this feature check be here at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted for now. Will have more to change/discuss to potentially better support Chrome's partial implementation in a follow-on.

Copy link
Collaborator Author

@sorvell sorvell May 12, 2024

Choose a reason for hiding this comment

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

Based on dicussion with @justinfagnani and suggestion in #549, check was removed.

Will revisit in follow-on.
@sorvell sorvell requested a review from justinfagnani May 7, 2024 22:35
@sorvell sorvell changed the title Improve issues related to formAssociated [scoped-custom-element-registry] Improve issues related to formAssociated May 8, 2024
Copy link
Contributor

@rictic rictic left a comment

Choose a reason for hiding this comment

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

A few minor comments, but overall LGTM

}

// Polyfill helper object
(window as Window)['CustomElementRegistryPolyfill'] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this global?

If it is global, should we check for its existence before writing? Something like:

(window as Window)['CustomElementRegistryPolyfill'] ??= {};
(window as Window)['CustomElementRegistryPolyfill']['formAssociated'] ??= new Set();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done and added comment.

@@ -19,6 +19,22 @@
* types, as though they were declared in a `declare global` in a module.
*/

interface Window {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer declare interface for google3 reasons (asks jscompiler not to rename)

Also, let's call it like, PolyfillWindow to not shadow the global Window interface

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

// Patch attachShadow to set customElements on shadowRoot when provided
const nativeAttachShadow = Element.prototype.attachShadow;
Element.prototype.attachShadow = function (
init: ShadowRootInitWithSettableCustomElements
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep a ...args here to pass through to the native, for future compat.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@sorvell sorvell merged commit aeb2038 into webcomponents:master Jun 6, 2024
5 checks passed
@sorvell sorvell deleted the form-associated-fix branch June 6, 2024 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[scoped-custom-element-registry]: Safari v16.4 focuses all custom elements
3 participants