danieldietrich / candid

Candid is a surprisingly fresh and frameworkless JavaScript library for building web applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error extending native elements in Safari

danieldietrich opened this issue · comments

Core issue: create a custom element which is a subclass of a native DOM element using the ES5 prototype chain. Current problem is the instantiation using new().

Looks like lit.dev does not support it. One more reason for us to do it!


This thread

https://dev.to/lkraav/comment/ad06

Browser support

See caniuse.com.

As of 2022-02-02

can-i-use

Solution / workaround

<!-- this should be on top of your HTML <head> scripts -->
<!-- it fixes customized built-in element in Safari and older browsers -->
<script src="//cdn.jsdelivr.net/npm/@ungap/custom-elements"></script>

There is a statement.

It's not possible to use custom elements without ES6 classes. That was a design decision necessary to achieve consensus at the January face-to-face meeting.

Actually, I am in doubt if extending native elements works at all in Safari. I guess, the current Candid implementation of ES5-style classes is correct.

Here is code that uses ES6-style classes and should work according to the spec.

Chrome

Chrome

Safari

Safari

It looks like I am right - Safari does not (and probably will never) support customizable built-in elements.

Screen Shot 2022-02-03 at 00 07 30

Furthermore:

All BaseClasses like Google-Lit, Stencil, SalesForce-LWC, extend from HTMLElement (Autonomous Elements)

Quick fix: include this polyfill

<!-- this should be on top of your HTML <head> scripts -->
<!-- it fixes customized built-in element in Safari and older browsers -->
<script src="//cdn.jsdelivr.net/npm/@ungap/custom-elements"></script>

Strategy / design decisions

  1. Candid will not ship a polyfill for Safari or other browsers. For now, an existing polyfill can be used.

  2. Candid does support customized built-in elements, even if Safari currently does not support them. This makes Candid stand out from Google-Lit, Stencil, SalesForce-LWC and other libraries for custom element creation. Safari may support customized built-in elements in the future. To use them now, a workaround is to include the fore mentioned polyfill.

  3. Candid leaves it up to the user to use customized built-in elements.