polymer icon indicating copy to clipboard operation
polymer copied to clipboard

Custom Elements polyfill is myopic about SVG

Open dominiccooney opened this issue 13 years ago • 5 comments

If I write this in Chrome:

<!DOCTYPE html>
<svg>
  <circle is="foo-bar" cx="50" cy="50" r="50" fill="red"></circle>
</svg>

and inspect the red circle, its prototype is SVGCircleElement.prototype. Likewise if I follow through with registering a definition, it stays "instanceof SVGCircleElement".

However if I write this:

<!DOCTYPE html>
<script src="polymer/polymer.js"></script>

<element name="foo-bar" extends="circle">
<script>
if (this !== window) {
  this.register({prototype: Object.create(SVGCircleElement.prototype, {})});
}
</script>
</element>
<svg> 
  <circle is="foo-bar" cx="50" cy="50" r="50" fill="red"></circle>
</svg>

then the circle becomes a HTMLUnknownElement.

In general it seems the polyfill assumes "extends" refers to HTML elements, and it also doesn't match up tag names of custom elements with what is on the prototype chain (for example if I make that extends="button", then my circle ends up with a prototype chain that leads to HTMLButtonElement.

dominiccooney avatar May 30 '13 02:05 dominiccooney

Absolutely agree about the issue subject, we semi-consciously avoided thinking about SVG elements. Thanks for bringing it up.

this.register({prototype: Object.create(SVGCircleElement.prototype, {})});

Fwiw, HTMLElementElement.register doesn't take a fully qualified prototype (in the polyfill), it only takes the custom prototype. The suffix prototype chain is established by the system based on the extends attribute.

This is almost the only thing that HTMLElementElement does. This is a general topic we need to discuss more fully I think (apart from the SVG support which would be good too).

sjmiles avatar May 30 '13 04:05 sjmiles

+1. It would be wonderful to be able to write higher-level svg-based charting libraries with custom elements.

zkat avatar Jun 14 '14 00:06 zkat

+1 for SVG support!

Emasoft avatar Jun 16 '14 23:06 Emasoft

+1 for SVG support.

adamthebig avatar Jan 27 '15 23:01 adamthebig

Closing this issue due to age and the release of version 1 release of Polymer - please feel free to re-open if this is incorrect.

tjsavage avatar Oct 23 '15 21:10 tjsavage