Skip to content

Commit 5c36f52

Browse files
authored
Prevent errors from @CustomElement decorator being called several times on the same element (#127)
1 parent 4e7f61e commit 5c36f52

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/gallery/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { ManifestScreenshot } from '../types/types';
55
import styles from './styles-gallery.scss';
66
import template from './template-gallery';
77

8-
@customElement('pwa-gallery')
98
export default class PWAGalleryElement extends LitElement {
109
@property({ type: Array }) screenshots: ManifestScreenshot[] = [];
1110
@property() theme: 'default' | 'apple_desktop' | 'apple_mobile' = 'default';
@@ -95,3 +94,7 @@ export default class PWAGalleryElement extends LitElement {
9594
)}`;
9695
}
9796
}
97+
98+
if (!customElements.get('pwa-gallery')) {
99+
customElements.define('pwa-gallery', PWAGalleryElement);
100+
}

src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LitElement, PropertyValues, html } from 'lit';
22
import { localized } from '@lit/localize';
3-
import { property, state, customElement } from 'lit/decorators.js';
3+
import { property, state } from 'lit/decorators.js';
44
import { changeLocale, isRTL } from './localization';
55

66
import { IRelatedApp, Manifest, IWindow, PWAInstallAttributes } from './types/types';
@@ -28,7 +28,6 @@ import templateApple from './templates/apple/template-apple';
2828
* @event {CustomEvent} pwa-install-gallery-event - App install gallery showed
2929
*/
3030
@localized()
31-
@customElement('pwa-install')
3231
export class PWAInstallElement extends LitElement {
3332
@property({attribute: 'manifest-url'}) manifestUrl = '/manifest.json';
3433
@property() icon = '';
@@ -331,4 +330,8 @@ export class PWAInstallElement extends LitElement {
331330
}
332331
}
333332

333+
if (!customElements.get('pwa-install')) {
334+
customElements.define('pwa-install', PWAInstallElement);
335+
}
336+
334337
export { PWAInstallAttributes };

src/templates/chrome/bottom-sheet/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type IProps = {
1515
import template from './template-bottom-sheet';
1616
import Utils from '../../../utils';
1717

18-
@customElement('pwa-bottom-sheet')
1918
export default class PWABottomSheetElement extends LitElement {
2019
static get styles() {
2120
return [stylesCommon, styles];
@@ -203,3 +202,7 @@ export default class PWABottomSheetElement extends LitElement {
203202
return html`${template(this.props.name, this.props.description, this.props.icon, this._callInstall, this.fallback, this.howToRequested)}`;
204203
}
205204
}
205+
206+
if (!customElements.get('pwa-bottom-sheet')) {
207+
customElements.define('pwa-bottom-sheet', PWABottomSheetElement);
208+
}

0 commit comments

Comments
 (0)