Effect UI Docs: TypeScript API vs. VibeLang + TSRX
Every chapter below comes directly from Effect-TS/ui/ai-docs. Flip the toggle (or press T) to switch the entire documentation between the standard @effect/ui TypeScript API and VibeLang's TSRX Typed JSX — with 100% identical type safety across Msg, R bubbling, exact DOM tag identity, VoidElement, keepAlive, and OpenTui.
Domain Schemas, Errors & Services
Every @effect/ui app starts with Schema models, typed TaggedErrors, and an Effect service that owns all I/O so components stay pure.
- schema + schema error eliminate duplicate const/type declarations and class boilerplate
- service Notes replaces Context.Service<Notes, {...}>()(...) with A!E!R shorthand
- effect { ... } + try replace nested Effect.gen / pipe chains
Building a Component, Commands & Subscriptions
A note editor with a queued Command.Service, an autosave stream subscription, controlled textarea, and TSRX JSX view with @if and on:* event handlers.
- @{ ... } TSRX view lowers directly to h.<tag> builders — same Html.Element<Msg, R, E, Node, Tag>
- effect function* autosaveTicks replaces Stream.tick + Stream.map boilerplate
- on:input, on:submit, and on:keydown:prevent check NoteEditorMessage at compile time
Composing Components, Queries, Slots & R Bubbling
Load a note with Query.Service, render child components and Feature.Service inside slots, and bubble GetNote | NoteActivity requirements straight through JSX.
- Requirements from <NoteEditor /> and <NoteActivity.render /> bubble through <article> into NotePageNoDeps
- Slots accept JSX directly: slots={{ summary: <h2>{note.title}</h2>, body: <>...</> }}
- Forgetting Component.provide([GetNote.layer, NoteActivity.toLayer(ActivityLog)]) is still a compile error
Reusable View Functions & Preserving Child R
Plain generic view functions take Html.H<M> and return builders or elements without erasing nested children's Effect service requirements.
- TSRX function body syntax `function Field<M, C>(h: Html.H<M>, options) @{ ... }`
- Generic `C extends View.Children<M>` retains the exact union of child requirements
- Self-closing `<input value={value} on:input={...} />` stays a VoidElement
Headless Components & Exact DOM Tag Safety
Headless components like Dialog and Listbox own ARIA, keyboard navigation, and state — and statically enforce exact HTML element tags on parts like dialog.trigger(<button>).
- <dialog.trigger><button ...>Cart</button></dialog.trigger> preserves exact tag "button"
- Swapping <button> to <div> is a compile error — impossible in stock TS JSX
- @for + @empty render cart items cleanly inside the modal popup
Keep-Alive Children & Literal-Key Safety
Keep hidden tabs or filtered list rows alive with h.keepAlive((s) => ...). Without a predicate, keys must be string literals — enforced identically in TSRX.
- Inside h.keepAlive((s) => @{ ... }), JSX automatically binds to `s: KeepAlive<Msg, Ends>`
- Dynamic non-literal key without a predicate triggers KeepAliveKeyHint compile error
- Ordinary .map((s) => <span>{s}</span>) never collides with keepAlive's `s`
Drawing Icons & Progress Charts with SVG
SVG tags check case-sensitive SVG attributes per tag (viewBox, stroke-width, stroke-dasharray), and <svg:text> lowers cleanly to h.svgText.
- Natural <svg viewBox="0 0 40 40"><circle ... /><svg:text>...</svg:text></svg>
- Mistyping viewbox or strok-width is still a compile error via per-tag SVG attr types
- Setup math (`const r = 16; const length = 2 * Math.PI * r`) lives right inside `@{ ... }`
Typed Routing, Exhaustive Views & Document Head
Key each page by AppRoute.printPath(route) and switch exhaustively across routes using native Vibe match inside TSRX.
- Exhaustive `match (route)` inside `<main>` rejects missing route branches at compile time
- Each page component (<NotesIndex />, <SearchPage />, <NotePage />) keeps its own R & key
- Zero boilerplate around header links and NotFound action button
Terminal Apps with OpenTUI (Multi-Host JSX)
The exact same TSRX syntax targets terminal UIs via @effect/ui-opentui — automatically scoping valid tags to OpenTUI (<box>, <input>, <select>, <text>, <b>) and rejecting HTML tags like <div>.
- OpenTui.component supplies OpenTui.H<TaskMessage> — writing <div> here is a compile error
- Controlled terminal focus ring via focused={model.focus === "input"} and on:enter / on:selectionChanged
- call:title="Tasks" and call:placeholder="New task..." invoke OpenTUI builder methods cleanly