Jadis
Jadis is a small TypeScript library over native Web Components. A component is a custom element: a class that extends Jadis. It draws its template once, as real DOM, then you change the nodes that need it when its state changes. There is no virtual DOM, no re-render, no reactive system and no framework runtime. Never bring React, Vue, Lit, a virtual DOM or a state library on top of it.
Written for @jadis/core@1.9.1. Documentation: https://bioleyl.github.io/jadis/ · Source: https://github.com/bioleyl/jadis
How to use this skill
- First time in a session: read this file, then references/agent-mistakes.md. It shows what models write from React, Vue and Lit habits, and what Jadis needs instead.
- Before writing: open the reference for the task (table in Where to look). Check every API you call against the installed version (The installed API).
- While writing: follow the rules. Copy the shape of the component below.
- Before delivering: run the self-check on your diff, fix what it finds, and report.
- Asked to review Jadis code: walk the rules and the mistakes file over the code, and report each finding with its place, the rule's name, the code quoted and a fix. Don't edit unless asked.
The project's own rules (AGENTS.md, CLAUDE.md, its README) and its consistent conventions win over this skill.
The model, if you know React
| You would write (React, Vue, Lit) | In Jadis |
|---|---|
| A function or class that renders again on every change | templateHtml() returns a Node, built once at the first connection, never again |
useState, ref(), @property, this.requestUpdate() |
this.useChange(initial, (value) => /* change the nodes */): a value with a callback, not a re-render |
JSX in render() with {state} interpolated |
JSX in templateHtml() for the structure; dynamic text written in callbacks with textContent |
ref, this.$refs, @query |
this.useRefs((ref) => ({ name: ref('#name') })): getters that query the shadow root |
useEffect and its cleanup |
onConnect(), and listeners added with this.on(), removed at disconnection on their own |
| Props | Public fields and methods; JSX props set properties; attributes through useChange(…, { attribute }) |
Callback props, $emit, dispatchEvent |
readonly events = this.useEvents<{ save: Item }>() then this.events.emit('save', item) |
| Context, Redux, Pinia, stores | A Bus shared by the components that need it, or a plain module |
key and list diffing |
You add, move and remove the row elements yourself, usually from a Map of id to element |
| React Router, vue-router | new Router(defineRoutes({…})).mountOn(element) |
| i18n libraries | Translator with defineTranslations, and this.useTranslation() |
A complete component
The shape to copy. One file per component, its CSS beside it.
// src/components/quantity-stepper.tsx
import { Jadis } from '@jadis/core';
import styles from './quantity-stepper.css?inline';
const MIN_QUANTITY = 1;
export class QuantityStepper extends Jadis {
// A custom element name: lowercase, with a hyphen, unique in the app.
static readonly selector = 'quantity-stepper';
// Public and named `events`: a parent registers on it, and JSX accepts `onValueChange`.
readonly events = this.useEvents<{ valueChange: number }>();
// The state. The `value` attribute, a JSX prop `value={3}` and `stepper.value.set(3)` all set it.
readonly value = this.useChange(MIN_QUANTITY, (value) => this.drawValue(value), { attribute: 'value' });
// Getters on the template: each access queries the shadow root. Never read them in the constructor.
private readonly _refs = this.useRefs((ref) => ({
decrease: ref<HTMLButtonElement>('#decrease'),
increase: ref<HTMLButtonElement>('#increase'),
output: ref('output'),
}));
// Runs once, at the first connection. Structure only: the callbacks fill in the values.
templateHtml(): Node {
return (
<div class="stepper">
<button id="decrease" type="button" aria-label="Decrease">−</button>
<output />
<button id="increase" type="button" aria-label="Increase">+</button>
</div>
);
}
templateCss(): string {
return styles;
}
// A task after each connection. Listeners added with this.on() go at disconnection.
onConnect(): void {
this.on(this._refs.decrease, 'click', () => this.step(-1));
this.on(this._refs.increase, 'click', () => this.step(1));
}
private step(delta: number): void {
this.value.set((value) => Math.max(MIN_QUANTITY, value + delta));
this.events.emit('valueChange', this.value.get());
}
// Draws the value it is given, whole: it may run again with the same value.
private drawValue(value: number): void {
this._refs.output.textContent = String(value);
this._refs.decrease.disabled = value <= MIN_QUANTITY;
}
}
QuantityStepper.register();
/* src/components/quantity-stepper.css */
:host { display: inline-block; }
.stepper { display: flex; align-items: center; gap: 0.5rem; }
A parent uses it by its class in JSX (importing the class registers it), or by its tag in HTML:
<QuantityStepper value={2} onValueChange={(quantity) => this.drawTotal(quantity)} />
<quantity-stepper value="2"></quantity-stepper>
The lifecycle
- Constructor: the shadow root is attached, empty. Field initializers run (
useRefs,useChange,useEvents,useAttributes). Nothing is rendered: reading a ref throws. - First connection (
appendChildinto the document):templateCss()andtemplateHtml()run once. Then, in the same call: attribute callbacks, thenuseChangevalues set before the connection (once each, with the latest value) andimmediateones, thenuseTranslationcallbacks. All before the browser paints. onConnect()runs a task later (setTimeout), not duringappendChild; not at all if the component was removed meanwhile.- Removal: a microtask later, the kill signal aborts, which removes every listener added with
this.on(),events.register()andonBus(), thenonDisconnect()runs. The DOM is kept. - Putting it back: the same DOM is reused, the template is not drawn again, attribute callbacks run only for the attributes that changed while it was away (a value set since is kept), and
onConnect()runs again. - A move (
append,insertBefore,replaceChildren,moveBeforeof an element already in the page) is not a removal: nothing runs, listeners stay.
So: onConnect() must be safe to run again, guard one-time work by what the DOM already holds, pass this.killSignal to fetch, and check this.isConnected after an await. Details: references/components.md.
Rules
Each rule has a short name; use the name when you cite it in a review.
The model
- Draw once, change in place.
templateHtml()builds the structure once. A change of state changes only the nodes it concerns (textContent,classList.toggle, a property, adding or removing one row). Never rebuild the template, never calltemplateHtml()yourself, never assigninnerHTMLto redraw. - Callbacks draw the whole value. A
useChangecallback writes the state it is given, so running it twice with the same value changes nothing. Replace values (set((list) => [...list, item])), never change them in place. - Listeners live with the connection. Listeners on your own template's nodes: a JSX
on…prop, orthis.on()inonConnect(). Listeners on anything that outlives the component (window,document, a bus, another component's events): inonConnect(), throughthis.on(),onBus()orevents.register(), or with{ signal: this.killSignal }. NeverremoveEventListenerby hand, never add them in the constructor. onConnectruns again. It runs after every reconnection, on the same DOM. Make it safe to repeat; guard one-time work (filling a list, a first fetch) by what the DOM or the state already holds, not a "done once" flag.- Never override the custom element callbacks.
connectedCallback,disconnectedCallback,attributeChangedCallbackandstatic observedAttributesbelong to Jadis. UseonConnect,onDisconnect,useAttributesanduseChange(…, { attribute }).
Components and data
- One selector, registered once, before use.
static readonly selectoris lowercase with a hyphen and unique: a second class on a taken name is silently ignored. Callregister()at the bottom of the component's module, and import a child's module before a parent renders it. - Properties down, events up. A parent sets a child's public
useChangefields (JSX props), calls its methods, or sets attributes. A child reports withthis.events.emit()on a publicreadonly eventsfield. ABusis for app-wide messages only. - JSX props set properties.
<user-card name="Ada" />assignselement.name, it does not set thenameattribute. Attributes come fromattrs={{ name: 'Ada' }}and from hyphenated names (data-*,aria-*). - Text through
textContent. Write data into the DOM withtextContent, properties, or JSX children. NeverinnerHTMLwith data: it is a script injection. - Styles in
templateCss(), the same for every instance. It becomes one stylesheet shared by all instances. Give the host a display (:host { display: block; }), and an instance its own values through CSS custom properties or classes, never through different CSS text. Shadow DOM is on: global CSS does not reach inside. - No names an element already has. A component is an
HTMLElement: never declaretitle,hidden,id,lang,dir,style,slot,translate,remove,click,focus,isConnectedor another inherited member as a field or method of your own.
Platform and verification
- The platform first.
fetchwith a signal,URL,Intl,<form>,<dialog>,<template>, CSS. No package for what a few lines of DOM do, and never a second component model. - Real APIs only. Check every Jadis call against the installed declarations before using it. Never write what an API "should" look like.
- Test the timing. In jsdom tests, what callbacks draw is there after
appendChild; whatonConnectdoes needs a task. Run the type check, the tests, and look at the page in a browser.
Where to look
Open only what the task needs.
| When you | Read |
|---|---|
| Start a project, set up Vite, TypeScript, JSX, plain JavaScript, or no build step | references/setup.md |
Write a component: refs, useChange, attributes, styles, shadow DOM, slots, the lifecycle in detail |
references/components.md |
Write templates: JSX rules, lists, conditions, forms, createElement, toTemplate, VNodes |
references/templating.md |
| Connect components: parent and child, events, buses, services | references/communication.md |
Add pages and navigation: routes, links, parameters, query, onRoute, canLeave |
references/routing.md |
| Translate the app | references/translations.md |
Render on the server, or with @jadis/fastify |
references/server-rendering.md |
| Write tests (Vitest, jsdom, Playwright) | references/testing.md |
| Want a worked example: a list, a form, a page that loads data, a dialog, an app shell | references/recipes.md |
| Need a signature | references/api.md |
| Are new to Jadis, or review code | references/agent-mistakes.md |
The installed API
- The version:
versioninnode_modules/@jadis/core/package.json. Its commented declarations, which work offline:node_modules/@jadis/core/dist/dts/(base-component.d.tsfor theJadisclass,helpers/,router/,translation/,server/). - The documentation of that version, as Markdown:
https://raw.githubusercontent.com/bioleyl/jadis/core-v<version>/packages/docs/<section>/<page>.md, the page's path on the site (/routing/routed-pagesgivesrouting/routed-pages.md). - An API this skill names that the installed version lacks is newer: suggest updating (
npm view @jadis/core version), or do without it. - An app on jlib (
@syware/jlib,jl-*components built on Jadis) also needs thejlibskill.
Self-check before delivery
Walk your diff once. Fix every "no", or say why it stays.
- Is the template drawn once, with every change made to the nodes it concerns, and no
innerHTMLredraw? - Does every
useChangecallback draw the whole value it gets, with values replaced, not changed in place? - Is every listener on something outside the component added in
onConnect()throughthis.on(),onBus(),events.register()or the kill signal, with noremoveEventListenerby hand? - Is
onConnect()safe to run again, withthis.killSignalgiven tofetchandthis.isConnectedchecked after anawait? - Is no custom element callback overridden, and no
observedAttributesdeclared? - Does each new component have a unique hyphenated selector,
register()at the bottom of its module, its children imported before it renders them, and:hostgiven a display? - Do parents set properties or call methods, children emit on a public
readonly events, and only app-wide messages go through a bus? - Are attributes set with
attrsor hyphenated names where an attribute is meant, and is data written withtextContent, neverinnerHTML? - Does no field or method reuse a name
HTMLElementalready has? - Did you check every Jadis API against the installed declarations?
- Do the type check and the tests pass, and did you look at the page in a browser? Say which you could not run.
Then report what the pass changed, as <file>:<line> — <what changed>, and end with one line: jadis self-check: 2 fixed or jadis self-check: clean.
What Jadis lacks or gets wrong: an issue
A bug in Jadis, or something every app has to work around, is fixed once in Jadis for all apps.
- Look for an existing issue first:
gh issue list --repo bioleyl/jadis --search "…". - Write the issue: what the app needed, what Jadis does instead (its version, a few lines that show it, the console's message), and what would solve it. One issue per problem.
- Show it to the person, who files it, or file it with
gh issue create --repo bioleyl/jadisonce they agree: the issue is public. - Meanwhile keep the app's workaround small and in one place, with a comment linking the issue.
