A click counter can keep its value in a local variable inside a generator. When two components need to read and change the same value, put it in a signal and read it during rendering.
1. Stateless Components (function)
If a component only transforms props into markup, write an ordinary JavaScript function. For example, this badge reads two props and returns a span.
export function Badge({ text, tone = 'neutral' }: { text: string; tone?: string }) {
return <span class={`pill ${tone}`}>{text}</span>;
}2. Stateful Components (function*)
Declare instance state before the loop. Each advance through the loop sees the current props and can yield a view.
import { type Ctx } from '@fierst/aster';
export function* Counter(
props: { start?: number; label?: string },
ctx: Ctx<{ start?: number; label?: string }>,
) {
// Setup (runs once)
let count = props.start ?? 0;
try {
// Render loop (runs on every event, prop change, or shared signal update)
for (props of ctx) {
const doubled = count * 2;
if (count < 0) {
yield <p>Count went negative!</p>;
continue;
}
yield (
<button onClick={() => count++}>
{props.label ?? 'Clicks'}: {count} (2× = {doubled})
</button>
);
}
} finally {
// Teardown (runs automatically when unmounted via gen.return())
console.log('Counter unmounted');
}
}How handlers read local variables
The click handler and the render loop share the same count variable. The handler increments it. On the next pass, the loop computes doubled from its new value. Conditional expressions such as disabled={!draft.trim()} work the same way. For lists, use a stable key when a row should retain its state through reordering. Try changing props and updating a list.
Props across updates
Change the label and step while keeping the current count.
import "./example.css";
function* Counter(props, ctx) {
let count = props.start ?? 0;
for (props of ctx) {
const step = props.step ?? 1;
yield (
<button class="btn primary" onClick={() => (count += step)}>
{props.label}: {count} (+{step})
</button>
);
}
}
export default function* App() {
let label = "Score";
let step = 5;
for (;;) {
yield (
<div class="specimen">
<header>
<h1>Scorekeeper</h1>
<span>Starting score · 10</span>
</header>
<div class="demo-box score-controls">
<label class="field">
Score label
<input bind:value={label} />
</label>
<button class="btn" onClick={() => (step = step === 1 ? 5 : 1)}>
Increment: +{step}
</button>
</div>
<Counter start={10} label={label} step={step} />
</div>
);
}
}
@media screen and (prefers-reduced-motion: no-preference) {
#example button.btn:enabled {
transition: transform 120ms ease-out;
}
#example button.btn:enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button.btn:enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
color-scheme: light dark;
--control-border: light-dark(#827a87, #928699);
--accent: light-dark(
oklch(0.45 var(--site-chroma, 0.15) var(--site-hue, 296)),
oklch(0.8 calc(var(--site-chroma, 0.15) * 0.74) var(--site-hue, 296))
);
--on-accent: light-dark(white, #18131e);
--ink: light-dark(#2b2630, #f4edf7);
--quiet: light-dark(#645d69, #c8bdcd);
--edge: light-dark(#d9d1df, #514857);
--paper: light-dark(#fffdfa, #27232c);
--canvas: light-dark(#f1edf2, #201c24);
font:
1rem/1.5 system-ui,
sans-serif;
}
:root[data-site-theme="light"] {
color-scheme: light;
}
:root[data-site-theme="dark"] {
color-scheme: dark;
}
body {
margin: 0;
padding: clamp(0.85rem, 4vw, 1.7rem);
color: var(--ink);
background-color: var(--canvas);
background-image: radial-gradient(var(--edge) 0.8px, transparent 0.8px);
background-size: 13px 13px;
}
.specimen {
max-width: 38rem;
margin: auto;
padding: clamp(1rem, 4vw, 1.65rem);
border: 1px solid var(--edge);
border-top: 3px solid var(--accent);
border-radius: 0.7rem;
background: var(--paper);
box-shadow: 0 4px 12px #211a2810;
}
.specimen header,
.specimen footer,
.demo-box,
.demo-row,
.demo-confirm {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.65rem;
}
.specimen header {
justify-content: space-between;
gap: 0.4rem;
margin-bottom: 0.9rem;
}
h1,
h3 {
margin: 0;
font-size: 1.25rem;
line-height: 1.2;
letter-spacing: -0.035em;
}
header > span,
.caption,
.readouts span,
dt {
font:
500 0.78rem/1.4 ui-monospace,
Consolas,
monospace;
color: var(--quiet);
}
p {
margin: 0.6rem 0 1rem;
}
.specimen footer {
margin-top: 1rem;
}
button,
input,
select {
font: inherit;
color: var(--ink);
border: 1px solid var(--control-border);
border-radius: 0.45rem;
padding: 0.45rem 0.72rem;
max-width: 100%;
background: var(--paper);
}
button {
cursor: pointer;
font-weight: 570;
}
button:hover {
border-color: var(--accent);
}
button:disabled {
opacity: 0.55;
cursor: default;
}
.primary {
color: var(--on-accent);
background: var(--accent);
border-color: var(--accent);
}
.danger {
color: light-dark(#913148, #ffb5c2);
background: light-dark(#fff3f4, #3c2930);
}
:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 2px;
}
.readouts,
.route-result {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.65rem;
margin: 0.6rem 0;
}
.readouts > div,
.route-result > div {
display: grid;
gap: 0.15rem;
padding: 0.65rem 0.85rem;
background: var(--canvas);
border-radius: 0.35rem;
}
.readouts output,
.ticket-body output {
font:
600 2.55rem/1.1 ui-monospace,
monospace;
letter-spacing: -0.08em;
color: var(--accent);
}
dd {
margin: 0;
font:
600 0.92rem/1.4 ui-monospace,
monospace;
}
.field {
display: grid;
gap: 0.22rem;
margin: 0.5rem 0;
color: var(--quiet);
font-weight: 550;
}
.field input {
width: 100%;
}
.score-controls {
align-items: flex-end;
}
.score-controls .field {
margin: 0;
}
.demo-list {
list-style: none;
margin: 0.6rem 0 0;
padding: 0;
}
.demo-list li {
border-top: 1px solid var(--edge);
padding: 0.37rem 0;
}
.checklist form,
.specimen > .demo-box {
margin: 0.5rem 0;
}
.pill,
.notice {
padding: 0.25rem 0.6rem;
color: var(--accent);
background: var(--canvas);
border-radius: 0.4rem;
}
.done {
text-decoration: line-through;
color: var(--quiet);
}
.demo-muted {
color: var(--quiet);
}
.trace-log {
max-height: 11rem;
overflow: auto;
padding: 0.7rem 0.8rem 0.7rem 2.7rem;
margin: 0.6rem 0 0;
background: light-dark(#322b38, #151119);
color: #f3e9fc;
font:
0.83rem/1.65 ui-monospace,
monospace;
border-radius: 0.45rem;
}
.trace-log li::marker {
color: #c6a3e5;
}
.trace button {
margin: 0.15rem;
}
.ticket-body {
display: flex;
align-items: center;
justify-content: space-between;
border-block: 1px dashed var(--edge);
padding: 0.65rem 0;
}
.ticket-body output {
display: block;
}
.perforations {
height: 2.3rem;
width: 5rem;
background: repeating-linear-gradient(
90deg,
var(--accent) 0 2px,
transparent 2px 4px,
var(--accent) 4px 5px,
transparent 5px 8px
);
}
3. Two-Way Form Bindings (bind:*)
@fierst/aster/vite (src/compiler.ts) lowers bind:value={draft}, bind:checked={task.done}, and bind:open={isOpen} into getter/setter tuples automatically:
export function* SearchBox() {
let query = '';
for (;;) {
yield (
<div>
<input bind:value={query} placeholder="Search..." />
<button disabled={!query.trim()} onClick={() => (query = '')}>
Clear
</button>
</div>
);
}
}Use a mutable local, a writable property, a signal held in a const or import, or an explicit [get, set] pair. For example, const query = signal('') works with bind:value={query}. Calling query() there supplies only its current value. Both compilers flag a known scalar at its JSX source location. A factory returning a binding is checked during server rendering or when the control mounts.
DOM handlers and custom binding setters can throw or return a rejecting promise. Aster forwards that failure to the nearest error boundary around the component that rendered the listener, or logs the event or binding name when there is no boundary. Return or await asynchronous callbacks to keep their errors in the event chain.
Use on:keydown={event => event.key === 'Escape' && event.currentTarget.blur()} for a native keyboard event. TypeScript infers both the event and the element. For application-defined events, augment the DOM interface GlobalEventHandlersEventMap with the event name and its CustomEvent<Detail> type to infer event.detail in JSX.
Bindings and keyed rows
Add a task and change its completion state.
import "./example.css";
export default function* App() {
let draft = "";
const items = [
{ id: "1", title: "Check the paper stock", done: true },
{ id: "2", title: "Pull a proof print", done: false },
];
const add = (e) => {
e.preventDefault();
if (!draft.trim()) return;
items.unshift({ id: crypto.randomUUID(), title: draft.trim(), done: false });
draft = "";
};
for (;;) {
const remaining = items.filter((i) => !i.done).length;
yield (
<div class="specimen checklist">
<header>
<h1>Before the press runs</h1>
</header>
<div class="demo-box">
<strong>{remaining} remaining</strong>
</div>
<form class="demo-box" onSubmit={add}>
<input bind:value={draft} aria-label="New task" placeholder="Add a task…" />
<button class="btn primary" disabled={!draft.trim()}>
Add
</button>
</form>
<ul class="demo-list">
{items.map((item) => (
<li key={item.id} class="demo-row">
<label class="demo-box">
<input type="checkbox" bind:checked={item.done} />
<span class:done={item.done}>{item.title}</span>
</label>
</li>
))}
</ul>
</div>
);
}
}
@media screen and (prefers-reduced-motion: no-preference) {
#example button.btn:enabled {
transition: transform 120ms ease-out;
}
#example button.btn:enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button.btn:enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
color-scheme: light dark;
--control-border: light-dark(#827a87, #928699);
--accent: light-dark(
oklch(0.45 var(--site-chroma, 0.15) var(--site-hue, 296)),
oklch(0.8 calc(var(--site-chroma, 0.15) * 0.74) var(--site-hue, 296))
);
--on-accent: light-dark(white, #18131e);
--ink: light-dark(#2b2630, #f4edf7);
--quiet: light-dark(#645d69, #c8bdcd);
--edge: light-dark(#d9d1df, #514857);
--paper: light-dark(#fffdfa, #27232c);
--canvas: light-dark(#f1edf2, #201c24);
font:
1rem/1.5 system-ui,
sans-serif;
}
:root[data-site-theme="light"] {
color-scheme: light;
}
:root[data-site-theme="dark"] {
color-scheme: dark;
}
body {
margin: 0;
padding: clamp(0.85rem, 4vw, 1.7rem);
color: var(--ink);
background-color: var(--canvas);
background-image: radial-gradient(var(--edge) 0.8px, transparent 0.8px);
background-size: 13px 13px;
}
.specimen {
max-width: 38rem;
margin: auto;
padding: clamp(1rem, 4vw, 1.65rem);
border: 1px solid var(--edge);
border-top: 3px solid var(--accent);
border-radius: 0.7rem;
background: var(--paper);
box-shadow: 0 4px 12px #211a2810;
}
.specimen header,
.specimen footer,
.demo-box,
.demo-row,
.demo-confirm {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.65rem;
}
.specimen header {
justify-content: space-between;
gap: 0.4rem;
margin-bottom: 0.9rem;
}
h1,
h3 {
margin: 0;
font-size: 1.25rem;
line-height: 1.2;
letter-spacing: -0.035em;
}
header > span,
.caption,
.readouts span,
dt {
font:
500 0.78rem/1.4 ui-monospace,
Consolas,
monospace;
color: var(--quiet);
}
p {
margin: 0.6rem 0 1rem;
}
.specimen footer {
margin-top: 1rem;
}
button,
input,
select {
font: inherit;
color: var(--ink);
border: 1px solid var(--control-border);
border-radius: 0.45rem;
padding: 0.45rem 0.72rem;
max-width: 100%;
background: var(--paper);
}
button {
cursor: pointer;
font-weight: 570;
}
button:hover {
border-color: var(--accent);
}
button:disabled {
opacity: 0.55;
cursor: default;
}
.primary {
color: var(--on-accent);
background: var(--accent);
border-color: var(--accent);
}
.danger {
color: light-dark(#913148, #ffb5c2);
background: light-dark(#fff3f4, #3c2930);
}
:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 2px;
}
.readouts,
.route-result {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.65rem;
margin: 0.6rem 0;
}
.readouts > div,
.route-result > div {
display: grid;
gap: 0.15rem;
padding: 0.65rem 0.85rem;
background: var(--canvas);
border-radius: 0.35rem;
}
.readouts output,
.ticket-body output {
font:
600 2.55rem/1.1 ui-monospace,
monospace;
letter-spacing: -0.08em;
color: var(--accent);
}
dd {
margin: 0;
font:
600 0.92rem/1.4 ui-monospace,
monospace;
}
.field {
display: grid;
gap: 0.22rem;
margin: 0.5rem 0;
color: var(--quiet);
font-weight: 550;
}
.field input {
width: 100%;
}
.score-controls {
align-items: flex-end;
}
.score-controls .field {
margin: 0;
}
.demo-list {
list-style: none;
margin: 0.6rem 0 0;
padding: 0;
}
.demo-list li {
border-top: 1px solid var(--edge);
padding: 0.37rem 0;
}
.checklist form,
.specimen > .demo-box {
margin: 0.5rem 0;
}
.pill,
.notice {
padding: 0.25rem 0.6rem;
color: var(--accent);
background: var(--canvas);
border-radius: 0.4rem;
}
.done {
text-decoration: line-through;
color: var(--quiet);
}
.demo-muted {
color: var(--quiet);
}
.trace-log {
max-height: 11rem;
overflow: auto;
padding: 0.7rem 0.8rem 0.7rem 2.7rem;
margin: 0.6rem 0 0;
background: light-dark(#322b38, #151119);
color: #f3e9fc;
font:
0.83rem/1.65 ui-monospace,
monospace;
border-radius: 0.45rem;
}
.trace-log li::marker {
color: #c6a3e5;
}
.trace button {
margin: 0.15rem;
}
.ticket-body {
display: flex;
align-items: center;
justify-content: space-between;
border-block: 1px dashed var(--edge);
padding: 0.65rem 0;
}
.ticket-body output {
display: block;
}
.perforations {
height: 2.3rem;
width: 5rem;
background: repeating-linear-gradient(
90deg,
var(--accent) 0 2px,
transparent 2px 4px,
var(--accent) 4px 5px,
transparent 5px 8px
);
}
4. Shared Cross-Component State (signal())
When multiple components (including Web Components) need to stay in sync, create a signal() in a shared module. Reading step() synchronously during rendering subscribes that component to changes:
import { signal } from '@fierst/aster';
export const step = signal(1);
export function* StepDisplay() {
for (;;) {
// Reading step() during rendering subscribes this component.
yield <span>Current step: +{step()}</span>;
}
}5. Async Components (async function*)
Use async function* to express loading states and sequential fetches as straight-line code. Every component receives ctx.signal (AbortSignal), which aborts immediately on unmount:
export async function* UserProfile(props: { id: string }, ctx: Ctx) {
yield <div class="skeleton">Loading user #{props.id}…</div>;
const res = await fetch(`/api/users/${props.id}`, { signal: ctx.signal });
const user = await res.json();
yield (
<article>
<h3>{user.name}</h3>
<p>{user.bio}</p>
</article>
);
}Recovering from a failed request
Choose a name, then simulate a 503. Retry from the error message to load a working profile.
import { ErrorBoundary, signal } from "@fierst/aster";
import "./example.css";
async function* ProfileCard(props, ctx) {
yield <p class="demo-muted">Fetching "{props.user}"...</p>;
await new Promise((r) => setTimeout(r, 250));
if (ctx.signal.aborted) return;
if (props.user === "broken") {
throw new Error("503 Service Unavailable");
}
yield (
<div class="demo-row">
<strong>{props.user}</strong>
<span class="pill">Profile loaded</span>
</div>
);
}
export default function* App() {
const selected = signal("Ada Lovelace");
for (;;) {
const user = selected();
yield (
<div class="specimen">
<header>
<h1>Profile lookup</h1>
<span>Simulated request · 250 ms</span>
</header>
<div class="demo-box">
<button
class="btn"
class:primary={user === "Ada Lovelace"}
onClick={() => selected.set("Ada Lovelace")}
>
Ada
</button>
<button
class="btn"
class:primary={user === "Grace Hopper"}
onClick={() => selected.set("Grace Hopper")}
>
Grace
</button>
<button class="btn danger" onClick={() => selected.set("broken")}>
Simulate 503
</button>
</div>
<ErrorBoundary
fallback={(err, reset) => (
<div class="demo-confirm">
<span>Request failed: {err.message}</span>
<button
class="btn primary"
onClick={() => {
selected.set("Ada Lovelace");
reset();
}}
>
Reset & Retry
</button>
</div>
)}
>
<ProfileCard user={user} />
</ErrorBoundary>
</div>
);
}
}
@media screen and (prefers-reduced-motion: no-preference) {
#example button.btn:enabled {
transition: transform 120ms ease-out;
}
#example button.btn:enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button.btn:enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
color-scheme: light dark;
--control-border: light-dark(#827a87, #928699);
--accent: light-dark(
oklch(0.45 var(--site-chroma, 0.15) var(--site-hue, 296)),
oklch(0.8 calc(var(--site-chroma, 0.15) * 0.74) var(--site-hue, 296))
);
--on-accent: light-dark(white, #18131e);
--ink: light-dark(#2b2630, #f4edf7);
--quiet: light-dark(#645d69, #c8bdcd);
--edge: light-dark(#d9d1df, #514857);
--paper: light-dark(#fffdfa, #27232c);
--canvas: light-dark(#f1edf2, #201c24);
font:
1rem/1.5 system-ui,
sans-serif;
}
:root[data-site-theme="light"] {
color-scheme: light;
}
:root[data-site-theme="dark"] {
color-scheme: dark;
}
body {
margin: 0;
padding: clamp(0.85rem, 4vw, 1.7rem);
color: var(--ink);
background-color: var(--canvas);
background-image: radial-gradient(var(--edge) 0.8px, transparent 0.8px);
background-size: 13px 13px;
}
.specimen {
max-width: 38rem;
margin: auto;
padding: clamp(1rem, 4vw, 1.65rem);
border: 1px solid var(--edge);
border-top: 3px solid var(--accent);
border-radius: 0.7rem;
background: var(--paper);
box-shadow: 0 4px 12px #211a2810;
}
.specimen header,
.specimen footer,
.demo-box,
.demo-row,
.demo-confirm {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.65rem;
}
.specimen header {
justify-content: space-between;
gap: 0.4rem;
margin-bottom: 0.9rem;
}
h1,
h3 {
margin: 0;
font-size: 1.25rem;
line-height: 1.2;
letter-spacing: -0.035em;
}
header > span,
.caption,
.readouts span,
dt {
font:
500 0.78rem/1.4 ui-monospace,
Consolas,
monospace;
color: var(--quiet);
}
p {
margin: 0.6rem 0 1rem;
}
.specimen footer {
margin-top: 1rem;
}
button,
input,
select {
font: inherit;
color: var(--ink);
border: 1px solid var(--control-border);
border-radius: 0.45rem;
padding: 0.45rem 0.72rem;
max-width: 100%;
background: var(--paper);
}
button {
cursor: pointer;
font-weight: 570;
}
button:hover {
border-color: var(--accent);
}
button:disabled {
opacity: 0.55;
cursor: default;
}
.primary {
color: var(--on-accent);
background: var(--accent);
border-color: var(--accent);
}
.danger {
color: light-dark(#913148, #ffb5c2);
background: light-dark(#fff3f4, #3c2930);
}
:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 2px;
}
.readouts,
.route-result {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.65rem;
margin: 0.6rem 0;
}
.readouts > div,
.route-result > div {
display: grid;
gap: 0.15rem;
padding: 0.65rem 0.85rem;
background: var(--canvas);
border-radius: 0.35rem;
}
.readouts output,
.ticket-body output {
font:
600 2.55rem/1.1 ui-monospace,
monospace;
letter-spacing: -0.08em;
color: var(--accent);
}
dd {
margin: 0;
font:
600 0.92rem/1.4 ui-monospace,
monospace;
}
.field {
display: grid;
gap: 0.22rem;
margin: 0.5rem 0;
color: var(--quiet);
font-weight: 550;
}
.field input {
width: 100%;
}
.score-controls {
align-items: flex-end;
}
.score-controls .field {
margin: 0;
}
.demo-list {
list-style: none;
margin: 0.6rem 0 0;
padding: 0;
}
.demo-list li {
border-top: 1px solid var(--edge);
padding: 0.37rem 0;
}
.checklist form,
.specimen > .demo-box {
margin: 0.5rem 0;
}
.pill,
.notice {
padding: 0.25rem 0.6rem;
color: var(--accent);
background: var(--canvas);
border-radius: 0.4rem;
}
.done {
text-decoration: line-through;
color: var(--quiet);
}
.demo-muted {
color: var(--quiet);
}
.trace-log {
max-height: 11rem;
overflow: auto;
padding: 0.7rem 0.8rem 0.7rem 2.7rem;
margin: 0.6rem 0 0;
background: light-dark(#322b38, #151119);
color: #f3e9fc;
font:
0.83rem/1.65 ui-monospace,
monospace;
border-radius: 0.45rem;
}
.trace-log li::marker {
color: #c6a3e5;
}
.trace button {
margin: 0.15rem;
}
.ticket-body {
display: flex;
align-items: center;
justify-content: space-between;
border-block: 1px dashed var(--edge);
padding: 0.65rem 0;
}
.ticket-body output {
display: block;
}
.perforations {
height: 2.3rem;
width: 5rem;
background: repeating-linear-gradient(
90deg,
var(--accent) 0 2px,
transparent 2px 4px,
var(--accent) 4px 5px,
transparent 5px 8px
);
}
Tracing a component lifetime
Change or finish a request and inspect the order of cleanup events.
import { signal } from "@fierst/aster";
import "./example.css";
const history = signal([]);
const record = (message) => history.update((lines) => [...lines.slice(-39), message]);
let finishRequest;
function Trace() {
return (
<ol class="trace-log" aria-label="Execution trace">
{history().map((line, i) => (
<li key={i}>{line}</li>
))}
</ol>
);
}
function* confirmation() {
let accepted = false;
try {
while (!accepted) {
record("Confirmation: next");
yield (
<button
onClick={() => {
accepted = true;
}}
>
Confirm
</button>
);
}
return true;
} finally {
record("Confirmation: finally");
}
}
function* Workflow() {
try {
const accepted = yield* confirmation();
if (accepted) yield <p>Confirmed</p>;
} finally {
record("Workflow: finally");
}
}
async function* Request({ id }, ctx) {
record("Request " + id + ": next, yield loading");
yield <p>Loading request {id}</p>;
record("Request " + id + ": next, waiting");
await new Promise((resolve) => {
const abort = () => {
record("Request " + id + ": aborted");
resolve();
};
if (ctx.signal.aborted) {
abort();
return;
}
ctx.signal.addEventListener("abort", abort, { once: true });
finishRequest = () => {
ctx.signal.removeEventListener("abort", abort);
resolve();
};
});
if (!ctx.signal.aborted) {
record("Request " + id + ": completed");
yield <p>Loaded request {id}</p>;
}
}
export default function* App() {
let id = 1,
open = true;
for (;;)
yield (
<section class="specimen trace">
<header>
<h1>Request timeline</h1>
</header>
<button onClick={() => id++}>Change request</button>
<button onClick={() => finishRequest?.()}>Finish request</button>
<button
onClick={() => {
open = !open;
}}
>
{open ? "Leave workflow" : "Open workflow"}
</button>
<Request id={id} />
{open && <Workflow />}
<Trace />
</section>
);
}
@media screen and (prefers-reduced-motion: no-preference) {
#example button.btn:enabled {
transition: transform 120ms ease-out;
}
#example button.btn:enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button.btn:enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
color-scheme: light dark;
--control-border: light-dark(#827a87, #928699);
--accent: light-dark(
oklch(0.45 var(--site-chroma, 0.15) var(--site-hue, 296)),
oklch(0.8 calc(var(--site-chroma, 0.15) * 0.74) var(--site-hue, 296))
);
--on-accent: light-dark(white, #18131e);
--ink: light-dark(#2b2630, #f4edf7);
--quiet: light-dark(#645d69, #c8bdcd);
--edge: light-dark(#d9d1df, #514857);
--paper: light-dark(#fffdfa, #27232c);
--canvas: light-dark(#f1edf2, #201c24);
font:
1rem/1.5 system-ui,
sans-serif;
}
:root[data-site-theme="light"] {
color-scheme: light;
}
:root[data-site-theme="dark"] {
color-scheme: dark;
}
body {
margin: 0;
padding: clamp(0.85rem, 4vw, 1.7rem);
color: var(--ink);
background-color: var(--canvas);
background-image: radial-gradient(var(--edge) 0.8px, transparent 0.8px);
background-size: 13px 13px;
}
.specimen {
max-width: 38rem;
margin: auto;
padding: clamp(1rem, 4vw, 1.65rem);
border: 1px solid var(--edge);
border-top: 3px solid var(--accent);
border-radius: 0.7rem;
background: var(--paper);
box-shadow: 0 4px 12px #211a2810;
}
.specimen header,
.specimen footer,
.demo-box,
.demo-row,
.demo-confirm {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.65rem;
}
.specimen header {
justify-content: space-between;
gap: 0.4rem;
margin-bottom: 0.9rem;
}
h1,
h3 {
margin: 0;
font-size: 1.25rem;
line-height: 1.2;
letter-spacing: -0.035em;
}
header > span,
.caption,
.readouts span,
dt {
font:
500 0.78rem/1.4 ui-monospace,
Consolas,
monospace;
color: var(--quiet);
}
p {
margin: 0.6rem 0 1rem;
}
.specimen footer {
margin-top: 1rem;
}
button,
input,
select {
font: inherit;
color: var(--ink);
border: 1px solid var(--control-border);
border-radius: 0.45rem;
padding: 0.45rem 0.72rem;
max-width: 100%;
background: var(--paper);
}
button {
cursor: pointer;
font-weight: 570;
}
button:hover {
border-color: var(--accent);
}
button:disabled {
opacity: 0.55;
cursor: default;
}
.primary {
color: var(--on-accent);
background: var(--accent);
border-color: var(--accent);
}
.danger {
color: light-dark(#913148, #ffb5c2);
background: light-dark(#fff3f4, #3c2930);
}
:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 2px;
}
.readouts,
.route-result {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.65rem;
margin: 0.6rem 0;
}
.readouts > div,
.route-result > div {
display: grid;
gap: 0.15rem;
padding: 0.65rem 0.85rem;
background: var(--canvas);
border-radius: 0.35rem;
}
.readouts output,
.ticket-body output {
font:
600 2.55rem/1.1 ui-monospace,
monospace;
letter-spacing: -0.08em;
color: var(--accent);
}
dd {
margin: 0;
font:
600 0.92rem/1.4 ui-monospace,
monospace;
}
.field {
display: grid;
gap: 0.22rem;
margin: 0.5rem 0;
color: var(--quiet);
font-weight: 550;
}
.field input {
width: 100%;
}
.score-controls {
align-items: flex-end;
}
.score-controls .field {
margin: 0;
}
.demo-list {
list-style: none;
margin: 0.6rem 0 0;
padding: 0;
}
.demo-list li {
border-top: 1px solid var(--edge);
padding: 0.37rem 0;
}
.checklist form,
.specimen > .demo-box {
margin: 0.5rem 0;
}
.pill,
.notice {
padding: 0.25rem 0.6rem;
color: var(--accent);
background: var(--canvas);
border-radius: 0.4rem;
}
.done {
text-decoration: line-through;
color: var(--quiet);
}
.demo-muted {
color: var(--quiet);
}
.trace-log {
max-height: 11rem;
overflow: auto;
padding: 0.7rem 0.8rem 0.7rem 2.7rem;
margin: 0.6rem 0 0;
background: light-dark(#322b38, #151119);
color: #f3e9fc;
font:
0.83rem/1.65 ui-monospace,
monospace;
border-radius: 0.45rem;
}
.trace-log li::marker {
color: #c6a3e5;
}
.trace button {
margin: 0.15rem;
}
.ticket-body {
display: flex;
align-items: center;
justify-content: space-between;
border-block: 1px dashed var(--edge);
padding: 0.65rem 0;
}
.ticket-body output {
display: block;
}
.perforations {
height: 2.3rem;
width: 5rem;
background: repeating-linear-gradient(
90deg,
var(--accent) 0 2px,
transparent 2px 4px,
var(--accent) 4px 5px,
transparent 5px 8px
);
}
6. Spread Props, Style Objects, and JSX Comments
Here a component gathers remaining props and forwards them to the button it renders:
export function ActionButton({ label, ...rest }: { label: string; [key: string]: any }) {
return (
<button {...rest} style={{ fontWeight: 600 }}>
{/* The JSX compiler removes this comment. */}
{label}
</button>
);
}7. Tree-Scoped Context (createContext, provide, useContext, <Provider>)
Use module-level signal() for client-wide state, and tree-scoped Context when passing data down a subtree or rendering concurrently on the server:
import { createContext, provide, useContext, Provider } from '@fierst/aster';
export const UserCtx = createContext<{ name: string } | null>(null);
export function Greeting() {
const user = useContext(UserCtx);
return <p>Hello, {user ? user.name : 'Guest'}</p>;
}
export function App({ user }: { user: { name: string } }) {
// Option A: imperative inside a parent component
provide(UserCtx, user);
return <Greeting />;
// Option B: declarative wrapper
// return <Provider context={UserCtx} value={user}><Greeting /></Provider>;
}Automatic async function* Prop Restarts
Aster compares each prop with Object.is. Changing id in <UserProfile id={selectedId} /> aborts the previous execution and starts a new one. Pass ctx.signal to the pending operation so it can settle and let the old generator reach its finally block.
Function props participate in this comparison. If a parent passes load={loadProfile}, replacing the loader restarts the child. Declare callbacks before the parent generator's render loop when they should keep the same identity across updates. An inline arrow inside the loop creates a fresh function on every render.
Start a request in the execution trace, change the selection, then leave a delegated confirmation. Compare the abort message with the order of the two cleanup messages.