X02

Error

State and reactivity

X02 — An effect that feeds itself

An effect re-runs when what it reads changes. One that writes, every run, something it reads starts the next run itself: the page never settles, and the browser overflows its stack.

What the compiler said

error[X02]: this effect writes `visits`, which it also reads, so each run starts the next and the page never settles --> src/App.wf:3:5 | 3 | effect { visits = visits + 1 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Work the value out with `derived` instead, or write it from the action that changes what it reads = docs: https://webfluent.monzeromer.dev/errors/X02

The fix

Broken

wf

page P(path: "/", title: "T", description: "D") { state visits = 0 effect { visits = visits + 1 } Heading("Visits {visits}").h1 }

Fixed

wf

page P(path: "/", title: "T", description: "D") { state visits = 0 Heading("Visits {visits}").h1 Button("Visit") { on click { visits = visits + 1 } } }

Work a value out with derived; change state from the action or handler that changes what it depends on.

Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).

lints cannot lower it: it would ship a broken page.