From DSL
to SwiftUI.
The server sends OpenUI Lang, the DSL the writer produces, as program text, with the component templates the program calls. The device compiles that text into elements with finished values. SwiftUI draws those elements from handles that the next compile reuses.
Follow one primitive.
P({
name: "Text", category: "text",
props: {
content: copy.text(),
role: token("type"),
weight: opt(token("weight")),
ink: opt(token("ink")),
},
})Text(content, role, weight?, ink?, ...)The catalog carries positions.
The catalog holds more than Swift uses. Primitive names, argument order and the slot role change behavior on the device. Token values, enums and data shapes are enforced only on the server. Component templates are not in the primitive catalog: they arrive with each run.
pick1_title = Text("Top scorers", "title2")zod checks the arguments against the primitive schema and the real dataset values.
content and role become properties. PrimitiveTypeRole maps title2 to a font size and line height.
The server checks meaning. The device builds structure from names and positions.
How do design tokens cross? +
They take three routes. Token names and validation live in src/primitives/tokens.ts and stay on the server. Spacing values travel as plain numbers in the program, so Swift reads gap directly. Type sizes are copied by hand into PrimitiveTokens.swift and render.tsx. Colors and component anatomy skip TypeScript, because the app bundles design_system.json directly.
TYPE in TypeScript ↗TYPE in Swift ↗Bundled theme ↗Props choose the container.
A layout is a tree of primitives that hold slots. StackPrimitive reads axis, gap and justify, then chooses a SwiftUI container. Nothing in the program describes a frame or a position.
pick2 = Stack("v", 8, @Each(d.answers.q1.rows, "r", Badge(r.name, "neutral")))VStack(alignment: .leading, spacing: 8) {
ForEach(Array(ids.enumerated()), id: \.element) { index, id in
PrimitiveNodeView(id: id)
.frame(maxWidth: .infinity, alignment: ...)
}
}OpenUISceneView
Removes Screen and lays its children out with the screen inset. Screen has no case in the switch.
OpenUIElementView
Reads properties from the handle and builds PrimitiveProps.
PrimitiveVisual
Switches on the kind string and returns the matching primitive view.
A container view
Reads its child slot with childReferences, so it tracks that one list.
PrimitiveNodeView
Wraps each child handle and returns to step 02 for the next level of the tree.
Stack("wrap", 8, children)FlowLayout(spacing: 8) { ... }A custom Layout. Children keep their own width and flow into rows.
How does a child know about its parent? +
Layout context travels through the SwiftUI environment. primitiveStackAxis tells Spacer which way to grow and lets a trailing column keep its own width. primitiveBleed gives full-bleed children their reach, and a Card resets it to its own padding. primitiveRailWidth sizes items in a rail.
Environment values ↗Screen removal ↗A component travels by name and expands on the device.
The writer calls Sports components such as PlayerValue by name, and the program keeps the call on the wire. Each component's template, an OpenUI Lang body over its parameters, travels as data. The device expands the call before it builds elements, so it still draws only primitives. Most templates are a tree of primitives inside a Card or a Stack. PlayerValue's template is a single data primitive, StepTimeline, and its complexity lives in one Swift view.
{ date: "2024-12-31", value: 116235970,
teamName: "Chelsea", teamId: 8455,
teamColor: { darkMode, lightMode } }{ value: "€97.7M",
caption: "Cole Palmer · Market value",
segments: [ { name, lineColor, tagColor, logo,
points: [ { x, label, value, display } ] } ],
ticks: [ { value, display } ] }Map one field from the record to the screen
d.answers.q1.chart.segments[2].lineColor = "#033cc1"line: color(item["lineColor"]) ?? palette.ink("primary")The stretch's line, its dot and its name while scrubbing. A value that does not start with # falls back to primary ink.
If existing primitives can draw it, write the component as a build that returns a tree. npm run openui:export prints the build as its template, and the template reaches devices with the next run, with no app release. If it needs new drawing or gestures, such as the stepped line and the scrub, add a primitive to PRIMITIVES, export the catalog and add a Swift case. The component then becomes a thin template over that primitive.
The wire carries program text.
The server never sends a tree. It sends text in chunks of complete statements, and the device parses and evaluates all of its text after each chunk. The device then compares the result with what is on screen.
event: templates
{ templates: [{ name, params, body }, ...] }EmptyNo blocks yet.
A writer statement alone never reaches the device. A part and all its children land in one event and one synchronous commit, so a card never appears half built. The cost is silence, because a long part shows nothing until its last statement passes.
What happens to a rejected statement? +
The server drops it and sends an issue event. Its text never reaches the device, and issues do not change what the app draws. The writer gets one repair round, with a message that lists its rejected statements and the problems. Questions still uncovered after that get a fallback part, which appears only in done.program.
Repair round ↗Statement validation ↗A view lives as long as its handle.
Each chunk produces a whole new scene, and SwiftUI must not rebuild the screen for it. An element id comes from its document key and its mount path. Commit reuses a handle when the id, the kind and the slot names all match.
pick1 = Text("Hello", "body")pick1 = Text("Bye", "body")The id and kind match, so commit reuses the handle and writes the new properties.
Swift views receive values, not paths.
A reference like d.answers.q1.rows never reaches a SwiftUI view. The compiler resolves it against the dataset and stores the result in the element. Views read that result from their handle, and @Observable tells SwiftUI when it changes. A component call resolves its record the same way, then hands the value to the template's fresh scope.
[
{ name: "Haaland", goals: 24 },
{ name: "Salah", goals: 19 },
{ name: "Palmer", goals: 15 }
]r1:ref:pick2Stack · axis "v", gap 8r1:ref:pick2/children/item:0Text · content "Haaland"r1:ref:pick2/children/item:1Text · content "Salah"r1:ref:pick2/children/item:2Text · content "Palmer"New data reaches a view through commit
rows: [
{ name: "Haaland", goals: 24 },
{ name: "Salah", goals: 19 }
]r1:ref:pick1Stack · no writer1:ref:pick1/children/item:0KeyValue · value 24r1:ref:pick1/children/item:1KeyValue · value 19 · no writeA follow-up holds the new dataset and program until done confirms the next revision. It then compiles once. The document key stays r1, so element ids match and commit writes only the value that changed. @Observable tells SwiftUI which handle moved.
Two kinds of state
Evaluated props
Every data reference and literal. Only commit writes them, and the views that read them update.
Local UI state
Toggle, Stepper, Chip, SegmentedControl and an open Section. Only that view can read it. Once set, it ignores later prop updates for that handle.
The language has no variables, so a Toggle cannot drive a Show. To change what another view shows, the program or the dataset has to change.
How does @Observable limit the work? +
registry and lastCommit are marked @ObservationIgnored. Update assigns only when a value differs, and slot set assigns only when the list differs by object identity. OpenUIElementView tracks properties, a container tracks its own slot, and the scene tracks root membership. These rules limit which writes happen.
Observation intent ↗What the bridge does not check.
Check these limits before you add a primitive or change an argument.
Nothing compares the digest
Swift decodes the catalog digest and never reads it. The server does not send one. Templates travel with each run, but a primitive newer than the app still fails the compile.
Parity stops at the tree
OpenUIFixtureTests compares compiled trees, for each expanded sample and for the same sample called by name. It tests no view code. It runs with make test and not in CI. A typo in a prop name read by a view passes every check.
Fixtures cover part of the catalog
check:sports-catalog looks for a Swift case for each kind in the sports fixtures. A new primitive outside those fixtures gets no renderer check on either side.
Actions wire in when a screen needs them
Button, IconButton and row actions call a dispatcher in the environment. It does nothing until a host sets primitiveContext, so these taps are inert today.
Compile everything. Write what changed.
The compiler comment describes the intent: it evaluates a complete immutable scene, then the runtime publishes only semantic changes. Each chunk therefore parses and evaluates the whole program on the main actor.
Components keep the same split. A template is data made of primitives, and it travels with the run. The device expands each call itself, so it still needs only the primitive catalog, and a new component that reuses existing primitives ships with no app release.
Documented compiler intent ↗