Skip to content

Sites & the seam

One declaration, five derivations

Every signal names the place its authoritative value lives. Everything else (the client code, the endpoints, the wire format, the trust boundary) is derived from that one word:

flowchart LR
    SIG["name: Site of T = default"]
    SIG --> L["Local"]
    SIG --> U["Url"]
    SIG --> SV["Server"]
    SIG --> D["Derived"]
    SIG --> SY["Synced"]
    L --> LT["compiled into the island —<br/>zero network"]
    U --> UT["the query string IS the store —<br/>links; the server re-renders"]
    SV --> ST["a facade on the server —<br/>await → POST command → region swap"]
    D --> DT["computed in the island from other signals —<br/>zero network, and nothing can write it"]
    SY --> SYT["RESERVED — local-first replica<br/>(see Status)"]

Local[T]: the browser owns it

search: Local[str] = ""
selected: Local[set[int]] = set()
dialog_open: Local[bool] = False

Compiles to the island. Reads and writes are S.get/S.set on the client signal store, and nothing crosses the wire unless you explicitly send it with a command. Local[set] is first-class: id in selected is a membership test, len(selected) compiles to .size, and mutation helpers keep updates immutable so change notification always fires. This is the site for view-state, the thing hypermedia stacks have no home for.

Url[T]: the address bar owns it

filter: Url[str] = "all"

There is no cell: a client read goes to location.search live, and the server reads the same query params into your context(). You set it with a link (<a href="../?filter=active">); a client write to a Url signal is a CompileError, because the value is the URL.

The disclosed trade-off

Url state is shareable and survives reload, and changing it is a real navigation that resets in-progress Local state (an open search, a selection). Neither behavior is wrong; the site is the choice. Put state in the URL exactly when you want link semantics.

Server[Facade]: the database owns it

issues: Server[IssuesFacade]

Inside handlers, the bare name is the injected facade (typed by your Protocol); in the template, it is whatever your context() returned under that name. On the client it is nothing at all: see the seam below. Handlers that touch it are commands: POST, re-render the one region, swap (Handlers & commands).

Derived[T]: computed from other signals

class Row(TypedDict):
    id: int
    title: str
    tags: list[str]


rows: Local[list[Row]] = []
tag: Local[str] = ""

visible: Derived[list[Row]] = [r for r in rows if tag == "" or tag in r["tags"]]
shown: Derived[int] = len(visible)
<li :each="r in visible" :text="r.title"></li>
<p :show="not visible">Nothing matches.</p>

A derived signal reads like any other, in a binder, a :each, a local handler or hand-written JavaScript. It recomputes at once when a signal it reads changes, so S.get("visible") right after S.set("tag", "red") is never stale. Everything downstream of a change is recomputed before anyone hears of it, so no binder or subscriber ever sees a mix of old and new values.

It stays real Python. Type checkers read the line as they read any other, and the component's .py runs it with the declared defaults on every command, so a value that raises with them is a CompileError: write xs[0] if xs else 0, not xs[0]. It reads Local and Derived signals declared above it, as Python requires, which rules out cycles. Its value needs a declared type and has to match it.

A list comprehension is allowed here, and only here: one for, a plain name as its target, and any number of if. In the .py a row is a dict, so it is r["title"], and r.title is a CompileError because CPython raises on it. Templates keep r.title. The rows are the same objects as the source's, so a row that stays in the list keeps its element.

So is sorted(), as the value, or as what a comprehension goes over: [r["id"] for r in sorted(rows, key=lambda r: r["at"], reverse=True)]. It orders text or numbers, and a lambda of one row is the only key=. It is stable, also with reverse=True, as in Python.

What it costs against :show. A :each over a shorter list removes rows, where a :show hides them. Filtering is slower on a long list, and anything typed in a removed row is lost when it comes back, unless a :show keeps it there. Write :show if that matters, and a derived list for what else needs the result.

Nothing can write it, which is what keeps a second source of truth out: an assignment, .append, reset, :bind (also on a row of a derived list), seed() and signal() are refused, and S.set throws. A command cannot read it either, as it runs on the server and would see the value for the defaults. For now only the root component of a tree can declare one.

Several writes in a row recompute once each, with no batching. A value can still raise on what the browser holds later, as xs[0] would on a list that became empty. As in Python, the error reaches whoever wrote the source, so guard it.

Synced[T]: reserved

The marker parses and the site is part of the design (a local-first replica reconciled by a sync engine), but no codegen or transport exists for it yet. Today's labelled stand-in for "shared, live" is mount_component(live=True): SSE-driven region refetch across clients (wire protocol). The full list of limits is in Status & roadmap.

The seam

The client/server boundary is a compile-time invariant, enforced at three explicit points. These are real compiler messages:

>>> a client binder reads a Server signal
CompileError: server-sited 'items' cannot be read on the client;
              DB-backed state stays on the server

>>> a client action assigns a Server signal
CompileError: cannot assign server-sited signal 'items' on the client

>>> a local handler loops over Server state
CompileError: refusing to compile a loop over server-sited 'items':
              DB iteration stays on the server

…plus one structural guarantee that outranks all three: the emitter has no code path that lowers database I/O. An await facade.method(...) can only compile to a cmd() POST; there is no case to forget and no convention to slip past. A component tree is also spliced into one module before emission, so the guarantee holds across composition: a Server-derived value can't sneak into a child's client handler through a prop or a provider.

So how does server data reach the screen?

Three paths are sanctioned, each explicit in the source:

  1. Server rendering. The template's Jinja renders rows from context(); a command re-renders the region with fresh data.
  2. Explicit per-row shipping. Inside a loop, data-* attributes (or a projection) carry named fields the client may read. t.id in a row-scoped binder reads the row's dataset.
  3. Signal patches. A server handler pushes values into client signals via signal("name", value) / reset("name"), riding the command response header.

You can never do any of these accidentally. That's the point.

Annotate context()'s return as a TypedDict and situ checks, at mount, that it declares every name the component template reads; and one level in, that a {% for t in items %} row model or an obj.field object has the fields the template reads. A forgotten key or a misspelled field is a CompileError at mount, ahead of the blank page it would have rendered. It is opt-in: a bare Mapping return is unchecked. The todos demo types its context() this way and shows the wrinkle it catches: the loop's row is the server row (title/done are rendered server-side), a richer shape than the client data-row projection. See Compile errors → Templates.