skatejs / web-components

[DEPRECATED] - The frictionless way to use the webcomponents/webcomponentsjs polyfills.
MIT License
17 stars 4 forks source link

HTMLElement.prototype.constructor not configurable #2

Closed bradleyayers closed 7 years ago

bradleyayers commented 7 years ago

When using the webcomponents.js custom element polyfill, window.HTMLElement is modified in such a way that breaks document.registerElement.

document.registerElement expects that if prototype is declared in the options, that its .constructor is configurable. When this requirement is not satisfied, an error like the following is emitted (this example comes from Chrome):

VM17049:156 Uncaught NotSupportedError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'aui-item-link'. Prototype constructor property is not configurable.

The problem comes from https://github.com/webcomponents/webcomponentsjs/blob/b77ca743edecb6ec262d4ffe8443708dbe0be49b/src/CustomElements/v1/CustomElements.js#L471.

The difference is observable in unpolyfilled:

> Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'constructor')
< Object {writable: true, enumerable: false, configurable: true}

vs polyfilled:

> Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'constructor')
< Object {writable: false, enumerable: false, configurable: false}

Note the difference in configurable.

treshugart commented 7 years ago

@bradleyayers I believe this is now fixes as the latest release includes the polyfill from https://github.com/WebReflection/document-register-element which doesn't have this issue.