Skip to content

Commit 635df62

Browse files
authored
Replace decorator with manual custom element registration (#59)
Optimize customElement definition logic to prevent errors on duplicate registration ```release-note None ```
1 parent 7263395 commit 635df62

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/search-widget/src/search-form.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import resetStyles from '@unocss/reset/tailwind.css?inline';
88
import { type DebouncedFunction, debounce } from 'es-toolkit';
99
import { uniqBy } from 'es-toolkit/compat';
1010
import { css, html, LitElement, unsafeCSS } from 'lit';
11-
import { customElement, property, state } from 'lit/decorators.js';
11+
import { property, state } from 'lit/decorators.js';
1212
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
1313
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
1414
import { HISTORY_KEY, MAX_HISTORY_ITEMS } from './constants';
1515
import baseStyles from './styles/base';
1616

17-
@customElement('search-form')
1817
export class SearchForm extends LitElement {
1918
@property({ type: String })
2019
baseUrl = '';
@@ -341,6 +340,9 @@ export class SearchForm extends LitElement {
341340
];
342341
}
343342

343+
customElements.get('search-form') ||
344+
customElements.define('search-form', SearchForm);
345+
344346
declare global {
345347
interface HTMLElementTagNameMap {
346348
'search-form': SearchForm;

packages/search-widget/src/search-modal.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import resetStyles from '@unocss/reset/tailwind.css?inline';
22
import { css, html, LitElement, type PropertyValues, unsafeCSS } from 'lit';
3-
import { customElement, property } from 'lit/decorators.js';
3+
import { property } from 'lit/decorators.js';
44
import { styleMap } from 'lit/directives/style-map.js';
55
import { OverlayScrollbars } from 'overlayscrollbars';
66
import overlayscrollbarsStyles from 'overlayscrollbars/styles/overlayscrollbars.css?inline';
77
import './search-form';
88
import baseStyles from './styles/base';
99

10-
@customElement('search-modal')
1110
export class SearchModal extends LitElement {
1211
@property({
1312
type: Boolean,
@@ -179,6 +178,9 @@ export class SearchModal extends LitElement {
179178
];
180179
}
181180

181+
customElements.get('search-modal') ||
182+
customElements.define('search-modal', SearchModal);
183+
182184
declare global {
183185
interface HTMLElementTagNameMap {
184186
'search-modal': SearchModal;

0 commit comments

Comments
 (0)