Add @b9g/crank/web-components (CrankHTMLElement) - #363
Open
brainkim wants to merge 1 commit into
Open
Conversation
brainkim
marked this pull request as ready for review
June 22, 2026 23:25
brainkim
force-pushed
the
web-components
branch
2 times, most recently
from
July 14, 2026 04:54
6f77ca6 to
3a9738f
Compare
brainkim
commented
Jul 16, 2026
| "./umd.js": { | ||
| "require": "./dist/umd.js" | ||
| }, | ||
| "./web-components": { |
Member
Author
There was a problem hiding this comment.
thoughts on shortening this to @b9g/crank/wc?
Member
Author
There was a problem hiding this comment.
Every other crank subpath is a spelled-out word (/standalone, /dom, /html, /jsx-runtime), so /web-components matches the family; /wc would be the lone abbreviation and less greppable. I lean /web-components, but the shorter import is a trivial change if you prefer it.
Adds a `CrankHTMLElement` base class for defining custom elements whose shadow content is rendered by Crank, so Crank components can be published as framework-agnostic web components.
brainkim
force-pushed
the
web-components
branch
from
August 11, 2026 22:53
3a9738f to
fa5c907
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the class-based
CrankHTMLElementfrom the RFC in #360 (closes #47).What's implemented
observedAttributes,events,formAssociated,shadowDOM,styles.rendermethod (this= element,ctx= arg), all four component forms via a stable bridge.requestUpdate()— microtask-batched, coalescing, safe before first connect.<slot>.on<type>handlers (lazy activate/deactivate; reassignment preserves listener order), typed fromCrankHTMLElement<{events: typeof Class.events}>(names-only for a tuple, typed payloads for an event map).static stylesderived once per class (string /CSSStyleSheet/ mixed array), adopted into the shadow root ordocument.ElementInternalsstays the author's.errorevent, thenreportErrorif unhandled.ShadowRoot(or document fragment) as a render root.Examples —
examples/web-components.tsxThe RFC's Scope examples:
x-blink(generator + timer, light DOM),x-marquee(shadow DOM, scopedstatic styles, imperativestart()/stop(), typedstatic events), andx-rating(form-associated,ElementInternalsvalue/validity, super-able reset/restore), plus a small demo wiring them together.Tests —
test/web-components.tsx, 33 passing in ChromiumBehavior: sync/async/generator/async-generator render; attribute re-render + same-value bail;
requestUpdate+ coalescing; generator-state persistence; shadow + slot projection; openShadowRootInitand closed mode;on<type>firing + listener ordering; in-component error fallback; render-error event (sync + async) +reportError; form FormData/reset/:disabled; light + shadow style adoption (deduped, mixed arrays); pre-upgrade property upgrade; light-DOM child replacement; move-vs-removal teardown.Integration: rendering a custom element through Crank's own DOM renderer; nested custom elements;
ctx.refresh/schedule/after; provisions within an element; computed shadow styles; accessor→attribute reflection. Plus a compile-only check of the event typing (tuple and event-map forms).Full suite green (606 passing);
tsc --noEmitclean; build emits the./web-componentsexport (.js/.cjs/.d.ts).Bugs the tests caught and this PR fixes: light DOM wasn't replacing authored children; a pre-connect
requestUpdatefired a spurious extra render; pre-upgrade properties weren't upgraded.Out of scope (deferred by the RFC)
SSR / declarative shadow DOM / hydration (RFC Appendix), the form-value SSR shim, customized built-ins, and a scoped
cssprop.🤖 Generated with Claude Code