SAP / ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.
https://sap.github.io/ui5-webcomponents/
Apache License 2.0
1.56k stars 267 forks source link

chore: call customElements.define synchronously #9857

Closed pskelin closed 1 month ago

pskelin commented 2 months ago

Before this change, importing a component module calls the UI5Element.define() base class method, which triggers some async work before calling customElements.define()

This causes frameworks like vuejs and react that check for property existence via prop in el to run before the element is defined, this check returns false and such frameworks set attributes (most notably boolean) as string resulting in checked="false" being treated as true by the components

With this change, the async work is triggered in the beginning of the define() call, but not awaited and customElements.define() runs as soon as the component is imported. The async work (waiting for the theme and i18n assets to be fetched) is now awaited in the connectedCallback so that the component is rendered once with the correct theme and language.

It is no longer necessary to call define() on the dependencies and to await this, as the dependencies are imported for use in the decorator, so their define() calls would have been executed and the elements will be defined by that point, since they also have synchronous define.