D02

Error

Data and assets

D02 — A persisted value storage cannot keep

persist writes its value to the browser's storage as JSON; a function, a file or a promise does not survive it.

What the compiler said

error[D02]: `persist pick` keeps a function, which cannot be written to the browser's storage --> src/App.wf:2:5 | 2 | persist pick = (x) => x + 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Keep what it is made from — a name, an id, the data — and build it again when it is read = docs: https://webfluent.monzeromer.dev/errors/D02

The fix

Broken

wf

page P(path: "/", title: "T", description: "D") { persist pick = (x) => x + 1 Heading("Pick").h1 }

Fixed

wf

page P(path: "/", title: "T", description: "D") { persist step = 1 Heading("Pick {step}").h1 }

Keep what it is made from — a name, an id, the data — and build the rest when it is read.

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.