- This implements clear errors & warnings when non-serializeable values are assigned to properties - Adjusts the size limit budget to allow better messages - Updates references to size limits |
||
|---|---|---|
| .husky | ||
| .vscode | ||
| assets | ||
| docs | ||
| examples | ||
| src | ||
| test | ||
| vendors/htm | ||
| .gitignore | ||
| .npmignore | ||
| .prettierignore | ||
| AGENTS.md | ||
| eslint.config.mjs | ||
| LICENSE | ||
| netlify.toml | ||
| package.json | ||
| pnpm-lock.yaml | ||
| pnpm-workspace.yaml | ||
| prettier.config.mjs | ||
| README.md | ||
| tsconfig.json | ||
| vitest.config.mjs | ||
Web Component Base
Note
What's next: correctness fixes. Thanks to feedback from teams building on WCB, our immediate focus is a set of state-corruption fixes: no attribute writes in the constructor, correct handling of empty-string and removed attributes (so
render()/onChangesare never silently skipped), removing the props proxy's first-write type lock, and safe cloning ofstatic propsdefaults. Detailed issues will follow.
🤷♂️ zero-dependency, 🤏 tiny JS base class for creating reactive custom elements easily ✨
When you extend the WebComponent class for your component, you only have to define the template and properties. Any change in any property value will automatically cause just the component UI to render.
The result is a reactive UI on property changes.
Links
Want to get in touch?
There are many ways to get in touch:
- Open a GitHub issue or discussion
- Submit a ticket via SourceHut todo
- Email me: hi@ayo.run
Inspirations and thanks
- htm - I use it for the
htmlfunction for tagged templates, and take a lot of inspiration in building the rendering implementation. It is highly likely that I will go for what Preact is doing... but we'll see. - fast - When I found that Microsoft has their own base class I thought it was super cool!
- lit -
lit-htmlcontinues to amaze me and I worked to makewcbgeneric so I (and others) can continue to use it
Size change log
A running record of how each correctness/feature change affects the WebComponent base class bundle, measured as min + brotli via size-limit. Baseline before the Phase 0 correctness work: 1.19 kB (limit 1.2 kB).
| Change | Size (min+brotli) | Limit | Reason & benefit |
|---|---|---|---|
| Move default-attribute reflection out of the constructor | ~1.19 kB (≈0) | 1.2 kB | Custom Elements Spec compliance. Constructors may not mutate attributes, so document.createElement on a class with static props threw NotSupportedError in real browsers. Defaults now reflect on first connect, and markup/SSR-provided attributes win. Pure code movement — no net size cost. |
| Safe prop cloning (functions/instances) + define-time validation | 1.31 kB (+0.12 kB) | 1.2 → 1.35 kB | No more DataCloneError. structuredClone of a function/class-instance default crashed construction. Defaults are now cloned per key (plain data deep-copied so instances don't share object/array state; non-cloneable values kept by reference), and a one-time warning names any default whose type can't reflect to an attribute. Limit raised to fit. |
Just keep building.
A project by Ayo
