Skip to content

Upgrading

On a 0.x version, a minor bump is the only one that may break you, always with migration instructions; see Status → Versioning. Each section below is the one to read when a build that worked on the previous minor no longer does.

To 0.7.0

dispatch_command returns None for a command that cannot run

Only code that calls situ.mount.core.dispatch_command directly is affected, such as an adapter of your own. It returned a CommandResult whose found was False; it now returns None, and CommandResult has no found field:

res = await dispatch_command(app, name=name, arg=arg, form=form, facade=facade, make_context=make_context)
if res is None:  # was: if not res.found:
    ...  # answer 404, with error_body(404, unknown_command(name))

A command can now also raise CommandError, which dispatch_command lets through for the adapter to answer with the error's status.

Declare the element types of a container you compute with

An operator, comparison, subscript or builtin call over a value of unknown type no longer compiles. It used to become the plain JavaScript operator, right only when the operands happened to agree. The common cause is a container declared without its element types:

tags: Local[set[str]] = set()  # was: Local[set]; for `t in tags`
lines: Local[list[Line]] = []  # was: Local[list]; for `len(lines)`, `sum(x.price for x in lines)`
anchor: Local[dict[str, str]] = {}  # was: Local[dict]; for `anchor["exact"]`

Line is a TypedDict naming the fields a row has. Truthiness (:show="lines", not anchor) and f-strings work on any value, so a container used only that way can stay bare. The error names the operand, and also covers a handler parameter whose type situ cannot infer: annotate it.

Load the runtime from its versioned URL

A layout of your own that loads /static/_rt.min.js keeps working. Switch it to the URL that changes with the file, so a browser never runs an old runtime against a new island:

<script defer src="{{ situ_runtime_url }}"></script>  <!-- was: src="/static/_rt.min.js" -->

A mount puts situ_runtime_url in its page context. A template rendered outside a mount can call situ.runtime_url().

FrontEnd.child_state holds Signal records

Only code that reads a compiled FrontEnd is affected. Each per-row signal in child_state[list] is now a Signal record. Read the default as child_state[list][name].default. The declared type, which the removed child_state_types held, is child_state[list][name].type.

_local in context() is deprecated

A context() that returns _local still works, with a DeprecationWarning. Return the same values through seed():

return {"count": total, **seed(count=total)}  # was: {"count": total, "_local": {"count": total}}

seed() refuses a name that is not a Local signal and a value JSON cannot encode, and sends the values again after every command, so the page follows the server. It does not change what a client reset() returns to, which stays the declared default; _local changed that too. A page whose handlers call reset() on a seeded signal now gets the declared default back.

To 0.6.0

0.6.0 turns many constructs that compiled and then did the wrong thing into CompileErrors, each naming the fix; the changelog lists them all. The changes below are the ones most likely to stop a build that worked on 0.5.0.

A value stored in a typed signal must have the declared type

Storing text in a Local[int], a number in a Local[str], or anything else of the wrong type is a CompileError, in a Local, in a row's own state, or as an argument to an annotated handler parameter. A DOM event's value is text, so convert it:

<input @change="n = event.target.value">        <!-- CompileError when n: Local[int] -->
<input @change="n = int(event.target.value)">   <!-- int() reads text as Python does -->

The old code stored the text, so :text="n + 1" showed 51. A bool still fits where an int is declared, as an int does where a float is.

Browser signals are not readable in Jinja

{{ n }} or {% if n %} over a Local, Derived or Synced signal is a CompileError: the server render has no value for it, so it showed blank. Read it with a binder:

<span :text="n"></span>
<p :show="n">…</p>

A command takes browser state as a parameter

A command runs on the server, where a Local signal is only its declared default. Reading one in a command, directly or through a helper, is a CompileError. Declare a parameter of the same name to have the browser's value sent with the command:

count: Local[int] = 0


async def save(count: str) -> None:  # was: async def save()
    await store.save(int(count))

A command reading a Url or Synced signal is refused too; pass it as a path argument, @click="save(page)". The server scaffold from situ new had this bug, so an app generated by an earlier version always saved 0: apply the change above to the generated save.

Url signals read in the browser are typed

page: Url[int] = 1 now reads as the number 7 with ?page=7 in a binder, and as the default when the query string holds something unreadable. It used to read as the text "7", so n + page concatenated. Hand-written JavaScript calling S.get("page") gets the number too, from the same decode.

A Url signal the browser cannot type and that has no browser default, such as Url[int | None] = None, is a CompileError when a binder reads it. Give it a default (Url[int] = 0) or read it only on the server.

A CompileError stops the server starting

mount_component, mount_static_component and mount_tree compile when they are called. A component that does not compile now raises at mount, where it used to serve a 500 on the first request. A test that expected the 500 should expect the error from the mount:

with pytest.raises(CompileError, match="..."):
    mount_component(...)

:upload needs mount_component

The ASGI and Flask adapters have no upload route, so an :upload binder on either is a CompileError at mount, as :virtual already was. Mount the component with mount_component(on_upload=...).

declui: options a screen ignores are refused

mount_model used to drop an option the screen does not use. It now raises: after= only on a create or edit form, row_actions=, actions_label= and pager_label= only on a server tracker. required=True on a write-form field that is not text is refused as well, since it disabled nothing; remove the option from the call.

Unified idiom: a lone { expr } has no <span>

<p>{ x }</p> compiles to <p :text="x"></p>. CSS or JavaScript that looked for the span (p > span) should target the element itself. An expression with anything beside it in the element, even whitespace, keeps its span.

FrontEnd.handlers holds records

For code that reads the compiler's front end: each entry of FrontEnd.handlers is a frozen Handler with params, prop_params, rides, row and state. Write front.handlers[name].params where you wrote front.handlers[name]["params"]. A command's path arity is on EmittedApp.path_args.

The other new checks: no action needed

Each of the other new CompileErrors stops code that was already silently doing the wrong thing. Examples are a command that could not route, a second binder of the same name on an element, a binder outside the <header> and the region, and a child component reading another's per-row state; the changelog lists the rest under "Changed". A component that worked as intended compiles as before.

To 0.5.0

0.5.0 aligns composition and name lookup with Python's scoping. That fixes several silent miscompiles, listed in the changelog, and breaks one thing.

A handler writes a signal only through global

A local handler that assigns a signal's name without declaring it global is now a CompileError that names the fix:

count: Local[int] = 0


def bump() -> None:
    count = count + 1  # CompileError: declare `global count`

In Python that line binds a local, and count = count + 1 raises UnboundLocalError. situ wrote the signal anyway, so the browser ran something other than the Python on the page. Add the declaration, which compiles to nothing:

def bump() -> None:
    global count
    count = count + 1

A parameter that shares a signal's name is the parameter: assigning it no longer writes the signal. A server command still cannot assign a signal at all; push it with signal() or reset(), as before.

Composed names: no action needed

A child component's generator or :each variable that shares a name with a prop, or with a name the parent passes in, is now renamed, leaving the outer name intact. A handler parameter no longer reads a Local of the same name. A component that relied on the old behaviour was computing the wrong value; one that did not compiles as before.

To 0.4.0

0.4.0 finishes the typed dialect and stops assuming a web framework. It has breaking changes, each announced in the changelog.

litestar is now an extra

The most likely break: pip install situ no longer installs Litestar, so importing the Litestar mount raises an ImportError that names the fix. The base install is the compiler plus situ.mount.asgi.asgi_app, which serves a component on any ASGI host and needs no web framework.

If you use mount_component, mount_tree, or declui's mount_model, add the extra:

pip install "situ[litestar]"      # or: uv add "situ[litestar]"

Nothing else changes: the mount API is identical. A FastAPI or bare-uvicorn user who was only ever on the ASGI adapter installs nothing extra and is unaffected.

A comparison the compiler cannot type is now a CompileError

Where an operand's type could not be established, situ used to emit a runtime guess (S.eqv) that compared both sides through Number(). The comparison reported 3 == [3] as true and made a non-numeric value (a status string, a filter id) never compare equal. That guess is gone; the comparison is refused at compile time instead.

The error names the operand and how to give it a type; any one of these fixes it:

  • Annotate the handler parameter: def go(id: int). (A bare parameter is now inferred from its call sites, so most comparisons type themselves; you see this error when the call sites disagree or pass something untypable.)
  • Declare the signal's element type: sel: Local[set[int]], with the element type spelled out.
  • Declare the row's record: data-row="IssueRow" on the row element plus a matching TypedDict, so t.id decodes to its real type.

Worked before/after examples: Compile errors → an operand whose type is not known.

Signal and Signals are gone from situ.siting

They were exported and documented, but the compiler never used them. It builds each app's signal table itself. If you reached for them, EmittedApp.signal_table is the real per-app projection. Site, TRANSPORT, and SIGNALS_HEADER are unchanged.

children= is gone from mount_component / mount_tree

Use components= (a resolution Context, e.g. Context.from_dir(DIR)), which has been the documented form for several releases and resolves the tags your tree actually reaches. mount_tree now requires it.

Set membership: no action needed

x in some_set now compiles to an element-wise Number() compare, because JavaScript's Set.has uses ===. True in {1, 2} was false in the browser and true in Python. If a set-membership test behaved differently in the browser than in Python, it now matches Python.