From 9051fd777d49f35522e95a47732651e76ff229c4 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Fri, 17 Oct 2025 00:22:59 -0500 Subject: [PATCH 1/3] fix: Types --- src/index.d.ts | 13 ++++--------- src/index.js | 22 +++++++++++----------- src/internal.d.ts | 8 ++++++++ 3 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 src/internal.d.ts diff --git a/src/index.d.ts b/src/index.d.ts index f92c6a3..8fc37c3 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,11 +1,4 @@ -import { h, AnyComponent } from 'preact'; - -type PreactCustomElement = HTMLElement & { - _root: ShadowRoot | HTMLElement; - _vdomComponent: AnyComponent; - _vdom: ReturnType | null; - _props: Record; -}; +import { AnyComponent } from 'preact'; type Options = | { @@ -46,9 +39,11 @@ type Options = * const klass = register(PreactComponent, 'my-component'); * ``` */ -export default function register

( +declare function register

( Component: AnyComponent, tagName?: string, propNames?: (keyof P)[], options?: Options ): HTMLElement; + +export = register; diff --git a/src/index.js b/src/index.js index 5a0aac3..5148a0d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,11 @@ import { h, cloneElement, render, hydrate, Fragment } from 'preact'; /** - * @typedef {import('./index.d.ts').PreactCustomElement} PreactCustomElement + * @typedef {import('./internal.d.ts').PreactCustomElement} PreactCustomElement */ /** - * @type {import('./index.d.ts').default} + * @type {import('./index.d.ts')} */ export default function register(Component, tagName, propNames, options) { function PreactElement() { @@ -13,13 +13,15 @@ export default function register(Component, tagName, propNames, options) { Reflect.construct(HTMLElement, [], PreactElement) ); inst._vdomComponent = Component; - inst._root = - options && options.shadow - ? inst.attachShadow({ mode: options.mode || 'open' }) - : inst; - if (options && options.adoptedStyleSheets) { - inst._root.adoptedStyleSheets = options.adoptedStyleSheets; + if (options && options.shadow) { + inst._root = inst.attachShadow({ mode: options.mode || 'open' }); + + if (options.adoptedStyleSheets) { + inst._root.adoptedStyleSheets = options.adoptedStyleSheets; + } + } else { + inst._root = inst; } return inst; @@ -49,9 +51,7 @@ export default function register(Component, tagName, propNames, options) { propNames.forEach((name) => { Object.defineProperty(PreactElement.prototype, name, { get() { - return this._vdom - ? this._vdom.props[name] - : this._props[name]; + return this._vdom ? this._vdom.props[name] : this._props[name]; }, set(v) { if (this._vdom) { diff --git a/src/internal.d.ts b/src/internal.d.ts new file mode 100644 index 0000000..c984364 --- /dev/null +++ b/src/internal.d.ts @@ -0,0 +1,8 @@ +import { h, AnyComponent } from 'preact'; + +export type PreactCustomElement = HTMLElement & { + _root: ShadowRoot | HTMLElement; + _vdomComponent: AnyComponent; + _vdom: ReturnType | null; + _props: Record; +}; From 8f41e93ba6fc2acfadcbad86e1684c1b582c58bd Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Fri, 17 Oct 2025 00:23:26 -0500 Subject: [PATCH 2/3] fix: ESLint configuration --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b96d25..3bd8b13 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "prepare": "npx simple-git-hooks", "build": "microbundle -f cjs,es,umd --no-generateTypes", - "lint": "eslint src/*.{js,jsx}", + "lint": "eslint src/*.js", "test": "npm run test:types & npm run test:browser", "test:browser": "wtr test/*.test.{js,jsx}", "test:types": "tsc -p test/", From 5e6eb4922312d7b002477b5ef1cc7a47cdd1f200 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Fri, 17 Oct 2025 01:22:15 -0500 Subject: [PATCH 3/3] ci: Merge the workflows (sorry for sneaking in) --- .github/workflows/ci.yml | 18 +++++++++++++++--- .github/workflows/size.yml | 24 ------------------------ 2 files changed, 15 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/size.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8df49bb..c7e3ace 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,16 +18,28 @@ jobs: with: node-version: 22 cache: npm + cache-dependency-path: '**/package-lock.json' - name: Install NPM dependencies run: npm ci - - name: build - run: npm run build - - name: test env: CI: true run: | npm run lint npm run test + + size: + name: Compressed Size + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: 'npm' + cache-dependency-path: '**/package-lock.json' + + - uses: preactjs/compressed-size-action@v2 diff --git a/.github/workflows/size.yml b/.github/workflows/size.yml deleted file mode 100644 index 61b2f1a..0000000 --- a/.github/workflows/size.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: CI - -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - build: - name: Build - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version-file: 'package.json' - cache: 'npm' - cache-dependency-path: '**/package-lock.json' - - - uses: preactjs/compressed-size-action@v2