P01

Warning

What is kept in the browser

P01 — A persisted value with no way forward

A persist at version: n with nothing to bring an older version forward, so what a returning reader had is discarded.

What the compiler said

warning[P01]: `items` is at version 2, and nothing brings version 1 forward --> src/App.wf:2:5 | 2 | persist items: [String] = [] { | ^^^^^^^ = help: A reader who last visited then loses what they had. Add `migrate 1 -> 2` = docs: https://webfluent.monzeromer.dev/errors/P01

Your editor offers this fix: Add migrate 1 -> 2. wf fix --code P01 applies it to every place it fits.

The fix

Broken

wf

store Cart { persist items: [String] = [] { version: 2 } }

Fixed

wf

store Cart { persist items: [String] = [] { version: 2 migrate 1 -> 2 { old } } } page P(path: "/", title: "T", description: "D") { use Cart Heading("{Cart.items.length} items").h1 }

Add a step for each older version: migrate 1 -> 2 { old.map(…) }.

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 may lower it:

"lints": { "P01": "off" } // wf-allow(P01)