Docs

Reference

The API documentation is generated from the platform’s source and documents every public symbol of Engine, Files, Html, Svg, Layout, Clipboard, Worker, Wire, Port, PortJson, Base64, WebCrypto, Order, Url and Web, including members inherited through public aliases: the authoring API. Operations only the engine may perform belong to unexposed modules. The engine’s storage and executable values are opaque; its implementation and the interfaces its hosts and test harnesses use live in the platform’s internal Core module, which apps cannot import. This page is the map of it. The spec language is in Testing.

Engine

AreaSymbolsGuide
Programsprogram, program_boot, program_store (an app with a store: ProgramProps, Boot -> Store and Boot -> Elem(StoreRoot(_))), Program(st) (st is the store’s type, inferred from main), Program.with_workers, Registration (made by a Worker task’s or preparation’s registration), Program.with_ports, PortRegistration, Boot, boot_storage, boot_session, boot_mediaGetting Started
ContextsRoot, StoreRoot(st) (the top of an app with a store), In(outer, s), Row(outer, item), Reach(ctx, st) (how a context reaches the store; a function that uses cells asks where [ctx.store : () -> Engine.Reach(ctx, _)])Thinking in Signals
SignalsSignal, const, Signal.map, Signal.map2 (which Roc’s record builder calls: { a: va, b: vb }.Engine.Signal is a signal of the record, the way a decision reads several cells), Signal.lift, Signal.lift_row, text literals/interpolation and Signal.to_text_signalThinking in Signals
The storecell, table, Cells(whole, st, h) (a description, built with the record builder: { a: .., b: .. }.Engine.Cells; a store of one cell is Engine.cell(init).map(|c| { c: c })), Cells.map, Cells.map2, Cells.with_reset, store, Stored(tag, st), Store(st, h), Store.cells, Store.with_initial, Store.after, Store.readShared State
Cells and writesCell(st, a), Cell.signal, Cell.state, Cell.set, Cell.update, Write(st)Shared State
Decisionshandle, handle_by (handlers generic over the payload), react, react_by (reactions): each from one pure function that returns a List(Write(st)); does (a handler from a list of writes, for a transition that needs nothing from the event)Shared State
Statestate, State(ctx, s) (a piece of state as one context sees it, local or shared), State.signal, State.lift, State.lift_rowLocal State, Events, and Forms
HandlersHandlerOf(ctx, p), Handler(ctx) (text), FilesHandler(ctx) (Received), State.update, State.update_by, State.set_value, State.set_value_by, HandlerOf.also (two handlers of one payload as one event), HandlerOf.lift, HandlerOf.lift_rowLocal State, Events, and Forms
StructureElem, element, text, text_s, when, switch, remount_on, derive, resource, Remote(output, error) (request: Idle, Pending; answer: Unanswered, Answered(output), Failed(error); remote.answered(), the latest answer as Try(output, [NoAnswer])), gather (one request per input), Gathered(output, error) (jobs: a JobState per input, Working, Answered(output) or Failed(error); all: a Remote of the whole list)Conditionals and Lists
Listseach, RowRef, RowRef.key, RowRef.field, RowRef.item (the whole item), RowRef.select, keyed, KeyedConditionals and Lists
Table viewstable_view, table_view_counted (also counts the rows kept into an attribute of the parent), TableViewProps (query, plan, window), sort_by (the sort value’s order, then the key’s), QueryPlan(k, v, s) (the explicit keep, sort, compare form), Window (start, count), every_row (the window that draws every row)Tables and Table Views
Ordered valuesOrder.pair, Order.asc, Order.desc, Order.directed, Order.utf8, Order.compare; types whose order_relative_to also works with ordinary Roc sortingTables and Table Views
URL valuesUrl.parse, checked literals, append_path_segments, append_query_param, resolve, request_target, path_segments, query_pairsBuilding URLs
AttributesAttr, attr, attr_s (present text, including empty), attr_presence (a signal of Absent or Present(text)), class, class_s, test_id, test_id_s, ref, ref_s (a signal of the reference’s name, including in a row; the empty name names nothing)Attribute values, Focus
Eventson (bare event type, text payload), on_with (text payload and typed Policy: prevent and stop, both false by default), on_click, on_files (Change, Drop or Paste, files payload), on_pointer (Down, Move, Up, Cancel, Pointer payload), on_pointer_capture, on_pointer_paced, on_scroll, on_size, on_seen (SeenProps), on_key (KeyProps), on_document_key (DocumentKeyProps, requires OutsideRows(ctx))Local State, Events, and Forms
PropertiesProp(a), Prop.value (Str), Prop.checked (Bool), Prop.pointer_zone (Str), prop, prop_sElement properties
Key dataKey (key, code, ctrl, alt, shift, meta, repeat, composing, heard), Chord (plain, with_ctrl, with_alt, with_shift, with_meta, primary), Keymap (prevent, keep, every, concat, outside_text)Keys and shortcuts
Reference commandsFocus, Blur, SelectText, ApplyValue, FocusInPlace, ScrollIntoView, ScrollTo; scroll_into_view, ScrollProps (block ?? Nearest, inline ?? Nearest, behavior ?? Auto), Align (Start, Center, End, Nearest), Edge (Keep, Start, End, Px(U32)), ScrollBehavior (Auto, Instant, Smooth)Focus and scrolling
Time and localeBoot.now_ms : I64, Boot.seed : U128, Boot.languages, Boot.zone; Zone (opaque, made only by boot and utc: zone.name(), zone.offset_at : Zone, I64 -> Try(I32, [OutsideZone])), utc; Fired(I64)Time, randomness and locale
Drafts and clipboardSessionStorageGet, SessionStorageSet, SessionStorageRemove, StorageChanges, StorageWriteFailures; guard_leave : Signal(ctx, Bool) -> Elem(ctx); Clipboard.text, Clipboard.html; Paste, Html.on_paste_textDrafts, Clipboard
AnimationViewTransition(List(Str)), a command in both Request and Command; marks one complete host-call batch, merges types in issue order, never marks mountAnimation
Pointer dataPointer: id, kind, button, buttons, modifiers, primary, at (Outside or In({ zone, x, y }) with fractions 0–10000)Pointer input and dragging
FilesFile, File.name, File.size, File.mime, File.slice (Err(OutsideFile) for a range outside the file), File.spans (the { start, len } ranges of n bytes that cover a file, for read!; Err(ZeroChunk) for n of 0), Received, FilesHandler (the generic handler family at Received), on_filesFiles
Operations on filesFile.upload (UploadProps: url, method ?? "POST", headers ?? [], timeout ?? Unlimited, credentials ?? SameOrigin), File.sha256, File.object_url (acting where the browser keeps the file), File.read_bytes, File.read_utf8 (reading it into the page; ReadProps: max_bytes ?? 8388608), FileError (Unreadable, TooLarge, InvalidUtf8, Unavailable, Refused, OutsideFile)Files
Saving and downloadingFile.save (a download command; SaveProps: name : [Same, Named(Str)]), File.fetch (File.FetchProps: url, method, headers, timeout : [Unlimited, Ms(U32)], cache ?? Default, credentials ?? SameOrigin), Fetched, FetchFailure, FetchError (for manual status classification) (Network, Timeout, Status, TooLarge, Refused)Files in Tasks
Effects in a worker jobFile.read! ({ start, len }), answering Try(_, [Unreadable, OutsideFile]), and File.contents!, answering Try(_, [Unreadable]), and File.contents_utf8!, Try(Str, [Unreadable, InvalidUtf8]); Files.build! (import pf.Files; BuildProps: name, mime : [Auto, Mime(Str)] ?? Auto, start_from : [Empty, From(File)] ?? Empty), Builder, Builder.append! (Try({}, [TooLarge])), Builder.append_file!, Builder.finish!Files in Tasks
HTTPhttp, HttpProps (defaulted method, headers, body, timeout, cache and credentials), Cache (Default, NoStore, Reload, NoCache, ForceCache), Credentials (SameOrigin, Include)HTTP options
Transfer progressTransfer, ProgressReaction, ProgressProps, State.on_progress, react_progress, Reaction.with_progressTransfer progress
Effectswatch, watch_changes, watch_latest, keep_current, on_post, on_post_by (sample a declared reading only when issuing the post), Outbox(item) (outbox({}), box.post(item), box.last(): Unposted or Posted(item)), Ask(output, error), Reaction(ctx, issued, result), State.on_result, react, react_by, Reaction.also (two reactions to one result), ignore, on_cleanup, cleanup, Request, Command (the requests that await no result, which is what a cleanup’s plan returns), Result (for deliberate raw plans), ask_of, raw, command, http, http_body, HttpError, WorkFault, FileError, and the plain data of port requests, PortMessage, PortFailure and PortDelivery, which the typed Port module wrapsEffects and the Browser

A component is not an API of its own: it is a type module whose view is handed the cells it uses (Components).

program_boot and program_store take ProgramProps, a record whose fields default to storage_keys: [], session_keys: [], max_inflight: 32, media: [] and zone_days: 366 (at most 7305 days each side of mount). Pass only the fields the app needs:

## An app may accept all declared defaults by passing empty props.
main = Engine.program_boot({}, |boot| Engine.text(boot.url))

Boot values an app declares belong in these props; catalogues of request kinds use Program.with_workers and Program.with_ports. Boot is also a record with defaults: URL /, empty storage, storage available, online and visible, empty available session storage, with no media pairs, time 0, seed 0, ["en-US"] and utc. Pure tests can name only the fields they use:

## A pure test names only the boot value relevant to its decision.
expect {
	boot : Engine.Boot
	boot = { url: "/articles" }
	boot.url == "/articles" and boot.online and boot.visible
}

Table

Table(k, v) is the value a table cell holds: rows by a key that has equality and a hash (import pf.Engine exposing [Table]). A decision changes it inside cell.update(...) with these operations, and each names the rows it touches; see Tables and Table Views.

AreaSymbols
Buildingfrom_list (Err(DuplicateKey(key)) for two rows with one key), empty
Keyed writesinsert (leaves the table unchanged for a key it holds), put (insert or replace), replace, update, remove (each leaves the table unchanged for a key it does not hold)
Whole rewritesupdate_all (change every row); a set of a new table replaces every row
Readingget (a Try(v, [Missing])), contains, len, fold and to_list (every row with its key; both in no particular order)
This turn’s changeschanges (each written key with its row as it was, or Rewritten), inverse (the writes that undo this turn’s, or Err(Rewritten)), apply (a list of Put(k, v) and Remove(k))

The changes serve an undo history and tests: in a pure test, store.after(writes).read(table).inverse() tells which rows a transition wrote.

Table bookkeeping belongs to the internal TableCore module and is absent from Engine.Table.

Html

Html is a typed vocabulary over Engine.element. Every helper is generic in its context. Accessible names go in aria-label, which the spec locators match. A helper ending _s takes a signal where its plain counterpart takes a constant; Html.p_s takes reactive text, for example.

AreaHelpers
Structurediv, div_s, div_attrs, section, section_s, section_attrs, h1, h2, h2_s, h3, p, p_s, p_attrs, span_s, pre_s, ul, li, link, label_for
Controlsbutton, button_s, icon_button, action_button, submit_button, text_input, number_input, textarea, checkbox, radio, select (Choices(a), Chose(a) or NotOffered), form, file_input (FileInputProps: selection : [Single, Multiple] ?? Single, accept : [Any, Types(Str)] ?? Any)
Dialogs and popoversdialog, DialogProps(ctx) (open, on_close : HandlerOf(ctx, Bool), modal : [Modal, NonModal] ?? Modal); popover, PopoverProps(ctx) (open, on_toggle : HandlerOf(ctx, Bool), dismiss : [Auto, Manual] ?? Auto); both open fields are Signal(ctx, Bool)
Ordered valuesOrder.pair, Order.asc, Order.desc, Order.directed, Order.utf8, Order.compare; types whose order_relative_to also works with ordinary Roc sorting
URL valuesUrl.parse, checked literals, append_path_segments, append_query_param, resolve, request_target, path_segments, query_pairs
LiteralsHtml.Markup, Svg.Markup, Markup.to_elem — Markup Literals
Attributesboolean, Hidden, hidden, hidden_s, InputType, aria_label, aria_label_s, aria_describedby, aria_invalid, disabled, flag, flag_maybe
Eventson_input, on_change, on_focus, on_blur, on_submit, on_cancel, on_drop_files, on_paste_files, on_pointer_down, on_pointer_down_capture, on_pointer_move, on_pointer_move_paced, on_pointer_up, on_pointer_cancel
Layout reportson_scroll, on_size, on_seen (SeenProps: ahead : Bool ?? False)
Zoneszone, zone_s (pointer-zone keys, with empty text marking no zone)

section(name, class, children) names a region for assistive technology and the spec locators (aria-label); it renders no heading, so put one among the children for a visible title.

Anything else is Engine.element(tag, attrs, children).

Html.unsafe_html(tag, attrs, html_signal) imports opaque browser-parsed HTML without escaping, validation or sanitization. It owns a stable wrapper without engine children; equal source prunes, changed source replaces all descendants. Imported descendants are outside spec locators and native text observation, and pictures refuse the wrapper even when empty. See Markup.

Web.Link checks link scheme policy. from_str returns Try(Link, [UnsupportedScheme(Str)]); literals use from_quote, text retains accepted authored text, and equality compares that text. Html.link requires it; Html.href and Html.href_s support custom layouts with explicit absence.

Layout

import pf.Layout provides plain report data with no engine dependency:

TypeFields
Scrolltop : U32, left : U32, rounded CSS pixels from the start edges
Sizewidth : U32, height : U32, content-box CSS pixels
Seenintersecting : Bool, ratio_permille : U16, from 0 to 1000

Attach them through Html.on_scroll, on_size and on_seen. Media uses ProgramProps.media, Boot.media : List((Str, Bool)), boot_media(boot, query) : Try(Bool, [Undeclared]) and the scoped MediaChanges(query) subscription, answered by Matches(Bool). See Scrolling and layout.

Worker

Worker runs registered Roc functions, tasks, in Web Workers; see Workers.

AreaSymbols
Taskstask, TaskProps(input, output, error) (name, run! : input => Try(output, error), timeout : [Unlimited, Ms(U32)] ?? Unlimited, on_dispose : [Stop, Keep] ?? Stop, on_cancel : [Stop, Finish] ?? Stop), Task(input, output, error), Task.registration, Task.name
Jobs from an effect siteTask.request, Task.result (a Try(output, Error(error))), Error(error) (Failed(error), Timeout, Refused, Lost(WorkFault)), Never (the error of a task that cannot fail)
Resourcesresource, resource_when (for a task or a preparation’s task), holding an Engine.Remote(output, Error(error)); gather (one job per input), holding an Engine.Gathered(output, Error(error)); status, a resource as one Status(output, error): Unasked, Working, Answered(output), Failed(error), Timeout, Refused or Lost(WorkFault)
Preparationspreparation, PreparationProps(init, state, error) (name, prepare! : init => Try(state, error)), Preparation(init, state, error), Preparation.task, PreparedTaskProps(state, input, output, error) (name, run! : state, input => Try(output, error), timeout, on_dispose, on_cancel, as a task’s), Preparation.registration (given its tasks’ registrations), PreparedTask(init, state, input, output, error), PreparedTask.registration, PreparedTask.name, PreparedTaskEntry(state), PreparedTask.request, PreparedTask.result, Question(init, input) (init, input)

Base64

Base64 is a pure RFC 4648 codec for binary data in text-only storage and formats. encode : List(U8) -> Str writes the standard alphabet with padding and no line breaks. decode : Str -> Try(List(U8), [NotBase64]) requires that canonical form: it rejects whitespace, URL alphabet symbols, missing or extra padding, padding before the end and nonzero unused bits. Empty text decodes to empty bytes. Both operations take linear time and output space.

## Keep a binary envelope in a text-only place, such as browser storage.
saved_envelope : Str
saved_envelope = Base64.encode([0, 255, 128, 1])

## A stored value is external input: handle malformed base64 before decoding
## the envelope itself. Base64 preserves bytes; it does not authenticate them.
read_envelope : Str -> Try(List(U8), [NotBase64])
read_envelope = |stored| Base64.decode(stored)

WebCrypto

WebCrypto provides scoped typed asks for cryptography. See Cryptography and bytes in text.

AreaSymbols
Secure bytes and hashingrandom_bytes : U64 -> Ask(List(U8), Error); digest : Hash, List(U8) -> Ask(List(U8), Error); Hash: Sha256, Sha384, Sha512
Key derivationKey (opaque, non-extractable, lifetime follows Roc references); derive_key : DeriveProps -> Ask(Key, Error); DeriveProps: required password, salt, iterations, hash ?? Sha256 (Sha256 or Sha512)
Authenticated encryptionencrypt : Key, EncryptProps -> Ask(Sealed, Error); EncryptProps: plaintext, associated ?? []; Sealed: iv, ciphertext, including the tag; fresh 12-byte IV generated for every encryption
Authenticationdecrypt : Key, DecryptProps -> Ask(List(U8), Error); DecryptProps: iv, ciphertext, associated ?? []; authentication failure returns no plaintext
FailuresError: Unavailable, TooLarge, InvalidParameters, NotAuthentic, Refused, Failed

Wire

Wire supplies the derived types of worker payloads. A task’s types decide what is sent; encoding and decoding belong to the worker boundary, rather than an app API for storing bytes. Payloads are one strict CBOR item within one compiled module.

AreaSymbols
PayloadsSendable, Error (InvalidCbor(position), MissingRequiredField(name))
Bulk bytesBytes, Bytes.from_list, Bytes.to_list
Custom codecsFormat, Enc, State, Items, Fields, Entries: opaque state types and the hooks used by codec derivation

Port

Port reaches services the page’s JavaScript supplies; see Ports.

AreaSymbols
Declaringcommand (CommandProps: name), call (CallProps: name, timeout : [Unlimited, Ms(U32)] ?? Unlimited), subscription (SubscriptionProps: name, delivery), Delivery (Latest, Every(n)), registrations (the catalogue for Program.with_ports, derived from an annotated record of ports and nested records of them), and each shape’s name
From an effect siteCommand.send, Call.ask, Subscription.ask; Call.request and Call.result, Subscription.subscribe and Subscription.message for an asker and pure tests; Error (Refused, Timeout, Threw(message), TooLarge, Closed, Undecodable(why), TooDeep)
Resourcesresource, resource_when (for a call), holding an Engine.Remote(output, Error)

PortJson

PortJson is the JSON format of port messages, derived from their types, with bytes and files carried beside the text.

AreaSymbols
MessagesSendable, encode, decode, describe, Message, Error
DerivationFormat, Out, State, Entries: the hooks the compiler’s codec derivation calls; apps never use them

Event payloads

A bubbling event reaches the nearest handler on its target or an ancestor. An event that does not bubble reaches only a handler on its target. The browser’s bubbles flag decides this, so custom event types follow the same rule. Engine.on accepts an open event name; a misspelt name or an event the element never raises runs no handler. A spec expecting that handler’s result catches it.

The attach function declares a payload kind. Text helpers use the text kind; on_files uses the files kind. The handler’s payload type must match. Policies are a typed record, never suffixes on the name. prevent prevents the default action, and stop prevents a bubbling event from reaching page listeners above the mount. stop has no effect on an event that does not bubble, so its own target can still receive it.

Event declarationPayload
on_click, on_click_with, button helpersClick: modifiers and optional authored nearest-link facts
Raw text-kind click, submitempty
inputthe control’s value
change"true" or "false" for a checkbox or radio, else the value
keydown, keyupthe key
focus, blurthe control’s value
change on a file input, drop, paste, with on_filesthe files, as Received (see Files)

Html.checkbox and Engine.on_checked deliver Bool on change from an HTML checkbox or radio. Html.select delivers Chose(value) from its current offered list, or NotOffered. These typed payloads use HandlerOf(ctx, p); from_payload_by converts an incoming payload using a current signal reading.

Engine.on_click and button helpers receive Engine.Click, with modifier flags and optional nearest-link facts. on_click_with declares a static policy; generic text-kind click listeners keep their payload.

Browser names and methods

Web owns Tag, AttrName, EventType and Method; Engine provides aliases for convenience. Names in literals are checked while compiling. For text built by an app, handle from_str’s result; text returns the exact original spelling. Tag and attribute values check context-free DOM name grammar. Namespace rules also depend on where an element is constructed. A well-formed computed name remains available when a vocabulary does not yet list it.

Web.Namespace distinguishes Html, Svg, MathML, None and an explicit Uri(text). Tag.in_namespace and AttrName.in_namespace take Web.NameProps: a required namespace and a prefix defaulting to Unprefixed. They return a checked result. local, prefix and namespace expose those retained facts; text gives their written qualified spelling. A colon in an ordinary raw name does not infer a namespace or prefix: under SVG, xlink:x is an unprefixed local name. SVG keeps such a name only when it starts with an ASCII letter and holds no ASCII capitals, so a tag literal holding a colon must follow that rule, and a computed one that does not is a contract error, naming its site, where it is created under SVG.

Explicit names retain exact case. Raw constructors resolve HTML case and the SVG/foreignObject child context in Roc before commands reach the runtime. Attribute identity is namespace URI plus local name; replacing that identity retains its existing prefix. Builtin namespace tags and their explicit URI spellings denote the same identity.

Qualification also checks that the browser can recreate the tuple exactly. In SVG and MathML, an unprefixed local name containing a colon must start with an ASCII letter and contain no ASCII capitals. A bare xmlns element in another namespace requires XML 1.0 characters in its URI and cannot use the reserved XML namespace URI. Other URI strings remain data; these construction limits do not impose XML grammar on ordinary DOM names.

A tag literal names a listed HTML element (case-insensitively), an exact-case SVG element, or a grammar-valid name with a hyphen. Literal names beginning exactly aria- use the parser’s ARIA vocabulary. Unknowns suggest close spellings and explain the explicit from_str constructor; it still accepts well-formed names newer than that vocabulary. A name alone does not supply a namespace or promise that its children obey the element’s content model.

Attribute literals class and data-testid point to class/class_s and test_id/test_id_s. An HTML element folds an attribute name’s ASCII case, so these checks and the ARIA check read the folded name: "CLASS" and "ARIA-LABLE" are refused like "class" and "aria-lable", and a correct ARIA name in another case, such as "aria-Label", is refused with its lowercase spelling, which SVG and MathML elements also read. Other names keep their case (viewBox). An event-handler attribute such as onclick is not refused by the constructors; a markup literal refuses it.

EventType accepts any nonempty type, including custom events, except a retired suffix or a text key handler: a literal is refused while compiling and from_str answers NotAnEventType, each naming the typed builder to use.

Method checks HTTP-token grammar and refuses CONNECT, TRACE and TRACK in any ASCII case. A literal containing lowercase is accepted only for the six methods Fetch normalizes: DELETE, GET, HEAD, OPTIONS, POST and PUT. Computed custom methods retain their spelling. HTTP requests and File factories share this one type; their GET and POST defaults remain checked values. An upload’s method is an UploadMethod, a Method other than any ASCII spelling of GET or HEAD, which carry no body: a literal "GET" does not compile, and Web.UploadMethod.from_str answers NoBody for a computed one.

Attribute values

attr and attr_s keep an attribute whose value is empty. Use attr_presence(name, signal) to choose Absent or Present(text); Present("") is distinct from absence and both cases prune equal updates without replacing the element, including in a row template.

Raw Boolean attributes follow the same rule: both "" and "false" remain present, and "true" remains that text. Use Html.boolean for a Boolean signal encoded as absence or present-empty, and Html.hidden or Html.hidden_s for Shown, Hidden and UntilFound. Html.flag_maybe omits an attribute when false through explicit Absent.

				Engine.element(
					"div",
					[
						Engine.test_id("note"),
						Engine.attr_presence("data-note", state.signal().map(|s| if (s.shown) Present("") else Absent)),
					],
					[Engine.text("The note's attribute is present only while enabled.")],
				),
				

Element properties

Engine.prop(row, value) and prop_s(row, signal) set a property from the closed table below. Their values are typed and equal updates are pruned, including in a row template. Html controls set them for you.

RowValue typeElementsBehaviorClaims attribute
Engine.Prop.valueStrinput, textarea, select, optionLive value, guarded while focused or composing; a select settles after option changesvalue
Engine.Prop.checkedBoolinputLive checked statechecked
Engine.Prop.pointer_zoneStrAny elementPointer hit-test zone; empty text marks no zone; no attribute mirrorNone

value and checked mirror their attribute; an empty value keeps value="", including on an option, while false checked removes its mirrored attribute. A claimed name used through an attribute constructor is a contract error on the row’s elements. On another element, such as a custom element or <progress>, attr("value", ...) sets only the attribute. A property on an element its row does not allow, or declared twice, is a contract error at mount. Applying value to a file input is a contract error at that command, including if its type changed through a signal.

Keymaps are private property rows attached only by on_key and on_document_key, paired with their handler. They have no public Prop constructor. Both props records require keymap : Signal(ctx, Keymap); on defaults to Down and stop to false. Key handlers have no static prevent field: the matching keymap entry decides it. ApplyValue(name) is a Request and Command that applies the last rendered value at a reference even while focused; it requires a declared Prop.value and waits for composition to end.

The dialog and popover helpers also pair private shown properties with Boolean native-event echoes. These are not public Prop rows or standalone codecs. Hiding applies in stream order; showing runs after the batch among commands and effects, with a later hide or removal invalidating an older queued show. A close/toggle echo settles its paired signal even when its handler writes nothing. See Dialogs and popovers for lifetimes, ownership restrictions and automatic dismissal.

Mount options

mountRocEngineApp({ wasmUrl, root, ...options }) fetches and compiles wasmUrl, mounts the app into the element root and returns the runtime. What an app means is decided in its Roc code and carried on its requests (a job’s timeout, a read’s max_bytes); a max… option is what this deployment allows, and caps what any request asks for. Every option is optional.

OptionDefaultWhat it sets or boundsGuide
dbg"console""off" suppresses debug values and fault text; the first observation explains that choice once. Other values refuse mountDebugging
onFaultnoneCalled with the diagnostic when the app breaks a contract and stopsGetting Started
viewTransitions"document""document" allows marked batches to start document-wide browser view transitions; "off" applies directly. Other values refuse mountAnimation
maxWorkersthe core count, at most 8Workers alive at once; further jobs wait in orderWorkers
workers"worker""inline" runs jobs on the page’s thread instead, one at a timeWorkers
workerUrlworker.mjs beside runtime.mjsWhere the worker script is servedWorkers
maxWorkerBytes128 MiBA worker whose memory has grown past it is ended after its job, its prepared state with itWorkers
maxOutputBytes256 MiBBytes one job may append to its builders; beyond it append! answers TooLargeFiles in Tasks
onWorkerFaultnoneCalled with { id, task, class, message } when a job is lostWorkers
maxFileBytes256 MiBBytes one read into the page takes, whatever its max_bytes; bytes one digest reads; bytes of one fetched body. Beyond it FileFailed(TooLarge). A job’s reads in a worker are not bounded by itFiles
maxCryptoBytes8 MiBCombined cryptographic operands and encryption tag, from 0 to 64 MiB; fixed digest output excluded; beyond it TooLargeCryptography
maxCryptoIterations1,000,000PBKDF2 iterations, at most 10,000,000; beyond it TooLargeCryptography
portsnoneThe page’s handlers, one per port the app declares; a missing or extra one refuses the mountPorts
maxPortBytes4 MiB (at most 64 MiB)One port answer or message, JSON text and bytes together; beyond it TooLargePorts
onPortFaultnoneCalled when a command handler or an unsubscribe function failsPorts
monitor{ history: 128, userTiming: false, payloads: false }What the work monitor keeps and reportsMonitoring Workers
storagethe page’s localStorageThe storage StorageGet and StorageSet use (an object with localStorage’s methods)Effects and the Browser
sessionStoragethe page’s sessionStorageThe independent service for declared session keys and session get/set/removeDrafts
maxPasteBytes4 MiBNonnegative safe integer; UTF-8 bytes accepted by Html.on_paste_text, beyond it TooLarge; zero permits only empty textPaste text
environmentbrowser fact readersnow() (safe integer or I64 BigInt), seed() (Uint8Array(16)), languages() and timeZone(days) supply boot facts; now() also stamps timer and interval callbacks. Optional Boolean online() and visible() readers at boot and on their events; visible() also chooses report drain scheduling. matchMedia(query) runs at boot and subscription creation; its object supplies Boolean matches and change listener methods, and is retained for that subscriptionEffects and the Browser
fetchthe global fetchThe function HTTP requests go through, for a page that scripts its own backendEffects and the Browser
manualEffectsfalseRequests wait for the caller (runEffect); reports wait for releaseReports(). Used by the spec runner in ChromeTesting
manualWorkfalseOnly worker jobs wait for runEffect; every other effect runs on its own; used by the repository’s long sessions in ChromeContributing

An unknown environment key or a non-function refuses mount. A reader that throws or returns the wrong type refuses mount at boot, or reports an executor fault on a later event. URL reads still use the document’s location; services and deployment limits use their own options.

The browser tests also pass manualIntervals (intervals tick only when the test says), window and document; an app’s page has no reason to set them.

First page

roc signals.roc build --picture URL... writes, for each URL, an index.html holding the app’s first frame: the native runner mounts the app for that URL and renders its ordinary mount batch, before any request is answered. The page stays inert until the module loads; the runtime then replaces the built nodes with its ordinary mount, in the same task, and lifts the inertness before the batch’s effects run. Built nodes are never reused. See Build a first page.

Attribute (no namespace)OnMeaning
data-roc-pictureThe template’s one mount rootThe root the build fills and the runtime replaces; removed once mounted
data-roc-picture-inert-parent=""The immediate HTML parent of a non-HTML (SVG, MathML) rootThat parent holds the inertness; its element children are the root and, optionally, a script with type="application/json" and data-roc-picture-envelope="1"
data-roc-picture-inert="added"The inert ownerWritten by the build when it added inert, so the runtime removes only that; reserved, never authored
data-roc-failedThe mount rootSet by the runtime on a root that held a picture when the module fails to load or the instance faults, with onFault called. A picture that never mounted stays inert until a retry or recovery succeeds

A picture carries markup only. A control’s value and checked appear through their attributes, a textarea’s value as its text and a select‘s through its options’ selected. Pointer zones and keymaps have no markup and arrive with the mount. A controlled dialog or popover is shown after a batch, never in markup, so a picture shows it closed.

Limits

ResourceBoundAt the bound
Awaited requests in flight32 (max_inflight)The reaction receives Refused
Follow-up chain depth per event64Contract error
Follow-up turns per event that follow-ups led to (those the event’s own turn queued are not counted)64 per in-flight slot, at least 4096Resource limit
HTTP timeout600 sCapped
One-shot timer delay0–2,147,483,647 msContract error outside the range, before admission
Interval period1–2,147,483,647 msContract error outside the range, before admission
Handlers for one event on one element1Contract error at mount, or at compile time when the default first page draws it; make one handler of two with also
Static attributes, children or holes per row template element255Resource limit
Live document-key handlers32 per instance; compile-time exclusion under rowsContract error at mount naming the site
Declared media queries32 distinct queries of 1–256 UTF-8 bytesContract error naming the query
Live observationsOne per element and kind, structurally bounded by live nodesNode resource bound; no fixed row-count cap
Leave guardsOne runtime flag and at most one listener, decided by live sitesNo slot or refusal; retained on poison, cleared on unmount/recovery
Deferred storage-write failuresPending recipient occurrences plus ingress entries at most 4096resource_limit; cancellation drops its pending identities, teardown clears the queue
Boot languages1–16 strings, at most 64 UTF-8 bytes eachDefault reader keeps the first that fit or en-US; invalid injected values refuse mount
Zone span and offsetszone_days each side (366 by default, at most 7305), 1–128 offsetsDefault probe shortens both ends to fit; OutsideZone beyond its inclusive span
Zone name64 UTF-8 bytesUnavailable or overlong default browser name is empty; invalid injected data refuses mount
Live DOM nodes2³² − 2Resource limit
Ingress entries (occurrences and reports)4096 waiting (queued while idle) and 4096 raised since the runtime last left idle: at most 8192An idle input at a full waiting budget drains the queue early; at a full raised budget a waiting transition applies and drains, and other overflow is a resource limit; a drain leaves at most 4096 at idle
Transition batches waiting for update1Inputs queue; a full queue forces application and draining
Wait for transition update1000 msApply directly and skip the animation
Transition observation historyNewest 4096 records and 1 MiB encoded type bytes, absolute U64 countOverwritten or oversized records fail observation; an oversized record clears prior history. Counter exhaustion disables observation; app execution continues
Replaceable reports per source1A newer report replaces the waiting payload in place
Wait for a report’s frame100 msTimer drains a visible page given no frames; hidden pages use a microtask
Manual scroll historyNewest 4096 commands, absolute U64 countOverwritten ordinals and counter exhaustion fail observation; app execution continues
Manual native UI callbacksAt most live controlled nodes, one coalesced toggle and a U64 close count per node; 20 s settle waitCounter exhaustion or timeout fails observation
Manual pointer log4096 records, taken after each input stepResource limit on overflow
Spec driver pointersOne mouse/pen gesture or up to 16 touches, without overlap between modesStep error before input; production pointer dispatch has no driver limit
Turns one drain delivers for raised entries4096; reports that waited for their frame spend noneResource limit; bounds a focus feedback loop even when only one event waits at a time
Payload kinds, element propertiesClosed tables with one-byte indicesUnknown numbers on the wire are contained as executor
Event policiesClosed table of 32 bitsUnknown fields do not compile; unknown wire bits are contained as executor
Live references with one nonempty name1, checked at the end of the turnContract error naming the name and both construction sites
Names in a worker catalogue64: tasks, preparations and each preparation’s tasksContract error at mount
Work timeout600 sCapped
A cancelled job of a task that says on_cancel: FinishIts timeout, else 600 s after it was asked forIts worker is ended, its prepared state with it
Workers alive at oncemaxWorkers (default the core count, at most 8)Jobs wait in order for a free worker
Prepared statesOne per workerA new input replaces the least recently used idle worker’s
A worker’s memorymaxWorkerBytes (default 128 MiB), checked after each jobThe worker is ended after the job, its prepared state with it; the console warns once per preparation whose state was too large to keep
Files an app holds at once64Further files an event carries are not delivered (Received.refused counts them); a download with no room is FileFailed(TooLarge)
Bytes one page read takesIts max_bytes (default 8 MiB), at most maxFileBytes (default 256 MiB)FileFailed(TooLarge), unread
Crypto keys an app holds64, separate from file handlesAnother derivation answers Refused
Crypto executor admission32 operations awaiting execution or running, including canceled running onesFurther operations answer Refused; they do not wait for capacity
Cryptographic byte operands and encryption tagmaxCryptoBytes, default 8 MiB, from 0 to 64 MiBTooLarge
PBKDF2 iterationsmaxCryptoIterations, default 1,000,000, at most 10,000,000TooLarge
Bytes one digest readsmaxFileBytes (default 256 MiB)FileFailed(TooLarge), unread
URLs one file gives16 ranges, revoked when the file is let goFileFailed(TooLarge)
Ports a program declares64, names 1 to 128 bytesContract error where the catalogue is built: a compile error for a top-level program, otherwise when the program is built
A port’s answer or messagemaxPortBytes (default 4 MiB, at most 64 MiB)TooLarge
Nesting of a port message512 containers, both waysA call or subscription: TooDeep, nothing sent; a command: not sent, reported to the console and onPortFault; an answer: Undecodable
Replaceable Latest report or Every backlog per subscription1 (Latest) or n ≤ 1024 (Every(n))Latest replaces; reports pinned by occurrences count within ingress. Every refuses the JavaScript’s emit
Port call timeout600 sCapped
Payload nesting128 levels of the app’s containers (each list, set, dictionary, record, tuple, tag with a payload and file)TooDeep: an input is not sent, an answer is not answered, and the worker is kept
NaN keys in one payload dictionary1NanKeys, as TooDeep
Bytes a job appends to its buildersmaxOutputBytes (default 256 MiB); files appended by reference do not countappend! answers Err(TooLarge)
Files in one job’s answer16TooManyFiles, nothing delivered, and the worker is kept
Room on the page for an answer’s filesThe page’s free slots among its 64The job is Lost(ResourceLimit), nothing delivered
Room on the page for a port’s answer or message with filesThe page’s free slots among its 64TooLarge, none of its files kept
Files and builders one job holds at once64The job is Lost(ResourceLimit)
A fetched bodymaxFileBytes (default 256 MiB)Err(TooLarge) in the typed fetch result

Errors

A typed timeout is Unlimited or Ms(ms) with at least one millisecond. Ms(0) is a contract error when the HTTP, file, port or worker request’s configuration is constructed; a top-level constant can therefore fail while compiling. Unlimited means no timeout, and a longer finite timeout is still capped at ten minutes. Raw request records keep their wire convention that timeout_ms: 0 means none.

Engine.timer(0) remains a legal one-shot time sample. Engine.interval requires a positive period; both use the browser’s maximum delay above. An invalid delay faults when the effect site issues it, before in-flight admission, rather than producing a wrapped browser delay.

The engine never repairs invalid input. A broken contract stops the app with a classified diagnostic naming the rule and, where there is one, the construction site, for example contract: duplicate key "r0" in each at site /3/0. The runtime keeps the last rendered page, reports the fault through onFault, and refuses further events.

ClassCause
contractA rule of the API was broken: a duplicate key in an each, two live references with one name, a switch value outside its cases, a row template that is not a single element, two handlers for one event type on one element, a property on an element its row does not allow or declared twice, an attribute with a name a property row claims on that element, a value property on a file input, an invalid media catalogue or an undeclared media subscription, a controlled helper with reserved attributes or a beforetoggle handler, a 33rd live document-key handler, ApplyValue without a declared value property at its reference, a decision whose list replaces a cell an earlier write of the same list wrote, two rows of a plan with its own compare that compare Same, a view’s row read after its key left the table in the same event, an effect feedback loop, an outbox posted twice in one turn, a worker task registered twice or asked for without being registered, a port declared twice or used without being declared or as another shape, a worker effect outside a job, a builder used after finish! or after the call that opened it returned, malformed boot or result bytes
resource_limitA bound in the table above
out_of_memoryThe Wasm heap could not grow
app_crashcrash in app code, or a Roc runtime error
expect_failedA failed expect in a development build
executorA failure while applying commands, including an external listener preventing a controlled show from reaching its requested state

recover() on the runtime mounts a fresh instance from the same module.

A fault inside a worker job stops only that worker. Its job answers WorkLost with the class (Lost(fault) in Worker.Error), the diagnostic goes to the console and onWorkerFault, and the page keeps working. WorkLost also reports unavailable (the browser has no workers, or a job running on the page’s thread with workers: "inline" reached an effect only a worker has) and executor (the worker script itself failed). A failure the task chose, Err(error) from its run!, is not a fault: it is the job’s answer, read as Failed(error).

Nothing a port’s JavaScript does stops the app. A call whose handler throws, rejects or answers something that is not JSON data answers Threw; a command handler’s failure goes to the console and onPortFault. A page whose ports option does not match the app’s declarations is refused before it mounts.

Protocol

The command stream, event records, boot bytes and program declarations are versioned together. The current protocol is version 22: every nonempty page batch starts with a flags byte, and a marked batch ends with TRANSITION (opcode 24). Worker answers have no page-batch header. Session storage adds section 11, and GUARD is opcode 25. Expanded names carry namespace, prefix and local name; elements carry an explicit child-container role, and literal comments use COMMENT (opcode 26). A port command the engine did not send, because its message nests past the port format’s 512 containers, is UNSENT (opcode 27). Engine-only boot section 13 carries the measured mount root. Typed clicks use payload kind 10; opaque HTML uses private property row 8. Both reuse the existing counters. Clipboard and failed storage writes have typed results; paste text has its own payload kind. HTTP carries cache, credentials and an optional progress interval; transfer reports use tag 26 and counter 47. The full wire protocol is Appendix B of design.md.

Debug observations on faults

onFault receives the same object as runtime.poisoned. Its dbg is { dropped, entries: [{ text, bytes }] } only for a call that trapped after writing debug text; otherwise it is null. bytes is the full UTF-8 length, not merely the retained prefix. onWorkerFault has the same field for a reported job fault. With dbg: "off", both fields are always null. Printing failure disables console output for the mount, but later fault text is still read. These are observations, never app results or scheduling inputs.