-
Notifications
You must be signed in to change notification settings - Fork 165
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
Conversation
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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
formAssociated
formAssociated
There was a problem hiding this 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'] = { |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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 beformAssociated == 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 tocustomElementRegistryPolyfill.formAssociated.add(tagName)
.Unconditionally installs polyfill.
Adds
registry
to ShadowRootInit