A confirmation dialog needs to pause the action that opened it. The user’s choice determines whether that action should continue.
Use yield* inside the calling generator. The delegated generator yields its own view while the choice is pending. When it returns a value, execution continues on the next line of the caller.
Example 1: Confirmation Dialog Returning boolean
function* confirmDelete(title: string) {
let choice: boolean | null = null;
while (choice === null) {
yield (
<div class="confirm-box" role="alertdialog">
<span>
Delete <strong>{title}</strong>?
</span>
<button onClick={() => (choice = false)}>Cancel</button>
<button class="danger" onClick={() => (choice = true)}>
Delete
</button>
</div>
);
}
return choice;
}
export function* TaskRow(
props: { task: Task; onDelete: (id: string) => void },
ctx: Ctx<typeof props>,
) {
let asking = false;
for (props of ctx) {
if (asking) {
// The caller resumes here with the user's choice.
const confirmed = yield* confirmDelete(props.task.title);
asking = false;
if (confirmed) {
props.onDelete(props.task.id);
return;
}
}
yield (
<li>
<span>{props.task.title}</span>
<button onClick={() => (asking = true)}>Delete</button>
</li>
);
}
}A confirmation that returns a decision
Try keeping the preview key, then revoking it. Each choice returns a boolean to the caller.
import "./example.css";
function* confirmRevoke() {
let decision;
while (decision === undefined)
yield (
<section class="specimen">
<header>
<h1>Revoke the preview key?</h1>
</header>
<p>The sample deployment will lose access. Keep the key to return without changing it.</p>
<footer>
<button onClick={() => (decision = false)}>Keep key</button>
<button class="danger" onClick={() => (decision = true)}>
Confirm revoke
</button>
</footer>
</section>
);
return decision;
}
export default function* AccessKey() {
let review = false,
revoked = false,
kept = false;
for (;;) {
if (review) {
revoked = yield* confirmRevoke();
kept = !revoked;
review = false;
}
yield (
<section class="specimen">
<header>
<h1>Deployment key</h1>
<span class="pill" role="status">
{revoked ? "Revoked" : kept ? "Active (kept)" : "Active"}
</span>
</header>
<dl class="route-result">
<div>
<dt>Environment</dt>
<dd>Preview</dd>
</div>
<div>
<dt>Permission</dt>
<dd>Read builds</dd>
</div>
</dl>
<footer>
<button class="danger" disabled={revoked} onClick={() => (review = true)}>
Revoke key
</button>
</footer>
</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
);
}
Example 2: Passing a result to the next checkout step
export function* CheckoutFlow() {
const shipping = yield* ShippingStep();
const payment = yield* PaymentStep(shipping);
const confirmed = yield* ReviewStep(shipping, payment);
if (!confirmed) {
yield <p>Order cancelled.</p>;
return;
}
yield <p>Order placed for {shipping.email}!</p>;
}Automatic Teardown Propagation
If CheckoutFlow unmounts while the user is halfway through PaymentStep, Aster calls gen.return() on the outer generator. JavaScript automatically propagates that termination into PaymentStep's finally block so timers, listeners, or locks are cleaned up cleanly.
Choosing who advances a workflow
A synchronous component advances once per scheduled update. While yield* is active, the delegated generator receives the value passed to .next(). A prop update can advance the current step. Arguments captured when the step began retain their values. Key the workflow by record ID when switching records should discard an outstanding confirmation.
An async generator advances again as soon as its previous yield resolves. Use it for finite sequences such as loading, awaiting a request, and displaying a result. Keep click-driven loops in synchronous generators. In an async generator a loop that repeatedly yields while waiting for a click can prevent the browser from dispatching that click.
Exceptions thrown inside a delegated step propagate to the caller's try/catch. Unmount calls .return() on the outer generator and runs active nested finally blocks from the inside out. Use ctx.signal for work that supports cancellation and ctx.refresh() to request a render after other asynchronous work finishes.
In the confirmation example, choose each outcome and watch which message the parent renders. Open Code + CSS and follow the boolean from the delegated step back into the parent.
Moving focus after a yield
Pass the component context into a delegated step to open a dialog once its controls and listeners are ready.
function* confirm(ctx: Ctx) {
let accepted: boolean | undefined;
while (accepted === undefined) {
yield (
<dialog
aria-label="Confirm change"
ref={(dialog) => ctx.afterRender(() => dialog.showModal())}
on:cancel={(event) => {
event.preventDefault();
accepted = false;
}}
>
<button
onClick={() => {
accepted = false;
}}
>
Cancel
</button>
<button
onClick={() => {
accepted = true;
}}
>
Confirm
</button>
</dialog>
);
}
return accepted;
}ctx.afterRender(callback) runs once, in registration order, immediately after this component's next successful DOM patch. This includes mounting, updates, async yields, and claiming server HTML. Refs point to their elements and synchronous children have mounted by then. The container can be detached, and browser paint and pending async children have their own timing.
Registration alone does not schedule a render. A callback registered inside another callback waits for the next patch. Unmount, replacement of the generator execution, or a failed render discards pending work. Server rendering skips these callbacks. A thrown error or a returned promise rejection goes to the component's error boundary while the execution is active.