scrml.dev v0.7.1
Reference › Errors

E-RI-002

A server-escalated function assigns to a reactive cell.

Error Compile-time SPEC §12.2 (normative)

What it means

Reactive state is client-side. When a function is escalated to the server — because its body contains ?{} SQL, a broadcast, or another server trigger — it no longer has a client-reactive referent, so an assignment to @cell has nothing to write to. This is one of the places the whole-stack compiler's placement inference becomes visible: the function moved, and the write no longer means what it meant.

Minimal reproducer

This is the exact source compiled against the linked compiler and verified to produce E-RI-002.

<program db="./app.db" title="p">
    <db src="./app.db" tables="users"/>
    <count> = 0
    function refresh() {
        const rows = ?{ SELECT * FROM users }.all()
        @count = rows.length
    }
    <button onclick=refresh()>refresh</button>
    <p>${@count}</p>
</>

How to fix

  1. Return the value and assign on the client. The server function returns data; a client-side caller writes the cell. This is the normal shape.
  2. For server-authoritative engine state, use a source cell. <engine for=T server=@source …> hydrates from a server-owned cell (§51.0.E) without a direct write.

Related

Specification

Normative text: §12.2, §6.6.9, §19.9.1, §37.7, §34. Spec lives at compiler/SPEC.md .

← Reference