fix(html): prevent tsdown from stripping custom element registrations (#703)

This commit is contained in:
rahim
2026-03-04 19:06:43 +11:00
committed by GitHub
parent 1edeadefed
commit 9a5dfab4e8
36 changed files with 337 additions and 68 deletions
@@ -0,0 +1,36 @@
import { describe, expect, it } from 'vitest';
import { safeDefine } from '../safe-define';
describe('safeDefine', () => {
it('registers a custom element', () => {
class TestElement extends HTMLElement {
static tagName = 'test-sd-register';
}
expect(customElements.get('test-sd-register')).toBeUndefined();
safeDefine(TestElement);
expect(customElements.get('test-sd-register')).toBe(TestElement);
});
it('does not throw when element is already registered', () => {
class TestElement extends HTMLElement {
static tagName = 'test-sd-no-throw';
}
customElements.define('test-sd-no-throw', TestElement);
expect(() => safeDefine(TestElement)).not.toThrow();
});
it('does not replace an existing registration', () => {
class Original extends HTMLElement {
static tagName = 'test-sd-no-replace';
}
class Replacement extends HTMLElement {
static tagName = 'test-sd-no-replace';
}
safeDefine(Original);
safeDefine(Replacement);
expect(customElements.get('test-sd-no-replace')).toBe(Original);
});
});