Skip to content

Commit

Permalink
fix(omi): missing tag name when redefining
Browse files Browse the repository at this point in the history
  • Loading branch information
dntzhang committed Apr 1, 2024
1 parent f6d85b4 commit b5c1c39
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/omi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omi",
"version": "7.6.6",
"version": "7.6.7",
"scripts": {
"start": "vite",
"dev-vite": "vite",
Expand Down
3 changes: 2 additions & 1 deletion packages/omi/src/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
* @param ctor - The constructor function for the custom element.
*/
export function define(tagName: string, ctor: CustomElementConstructor): void {
// 重复定义也需要挂载 tagName,防止重复定义时候被使用没有 tagName 当作函数
Object.defineProperty(ctor, 'tagName', { value: tagName, writable: false })
if (customElements.get(tagName)) {
console.warn(
`Failed to execute 'define' on 'CustomElementRegistry': the tag name "${tagName}" has already been used with this registry`,
)
return
}
Object.defineProperty(ctor, 'tagName', { value: tagName, writable: false })
customElements.define(tagName, ctor)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/omi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export { Signal } from 'reactive-signal'
export { css } from './css-tag'
export { mixin, globalCSS } from './options'
export { registerDirective } from './directive'
export const version = '7.6.6'
export const version = '7.6.7'

0 comments on commit b5c1c39

Please sign in to comment.