Skip to content

Commit

Permalink
Prevent double init in web components (#2611)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardl authored Mar 14, 2022
1 parent 2478386 commit b12cbb7
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions client/src/luigi-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ export class LuigiElement extends HTMLElement {
const template = document.createElement('template');
template.innerHTML = this.render(ctx);
const attCnt = () => {
this._shadowRoot.appendChild(template.content.cloneNode(true));
Reflect.ownKeys(Reflect.getPrototypeOf(this)).forEach(el => {
if (el.startsWith('$_')) {
this._shadowRoot[el] = this[el].bind(this);
}
});
const elementsWithIds = this._shadowRoot.querySelectorAll('[id]');
if (elementsWithIds) {
elementsWithIds.forEach(el => {
this['$' + el.getAttribute('id')] = el;
if (!this.__initialized) {
this._shadowRoot.appendChild(template.content.cloneNode(true));
Reflect.ownKeys(Reflect.getPrototypeOf(this)).forEach(el => {
if (el.startsWith('$_')) {
this._shadowRoot[el] = this[el].bind(this);
}
});
const elementsWithIds = this._shadowRoot.querySelectorAll('[id]');
if (elementsWithIds) {
elementsWithIds.forEach(el => {
this['$' + el.getAttribute('id')] = el;
});
}
this.afterInit(ctx);
this.__initialized = true;
}
this.afterInit(ctx);
this.__initialized = true;
};
if (this.luigiConfig && this.luigiConfig.styleSources && this.luigiConfig.styleSources.length > 0) {
let nr_styles = this.luigiConfig.styleSources.length;
Expand Down

0 comments on commit b12cbb7

Please sign in to comment.