Layer-4 token transformer: wraps bare {@field} expressions in
<span data-lavash-display="field"> when :field is an
optimistic state field or an optimistic calculation.
The JS hook reads data-lavash-display to know which DOM node
to swap on optimistic state change. Without the wrapping span,
the bare interpolation just emits text — the optimistic patch
can't find a stable element to update.
What it skips
metadata[:layer] == :base— layer-2-only modules don't need optimistic display wrapping; the warning suppressed in Base mode is paired with no-op wrapping here.- Non-optimistic refs —
{@count}for astate :count, ...that doesn't setoptimistic: trueis left alone. (The oldLavash.Template.TokenTransformeremitted a diagnostic warning here; that warning lives inLavash.Optimistic.NonOptimisticWarnernow.) - Bare-var refs (
{item}from a:forloop) — never wrapped, since loop vars aren't assigns. - Body_exprs whose immediate parent is already a display
wrapper or a
data-lavash-manualblock. - Body_exprs inside
<textarea>,<option>,<title>— the browser treats body content as form values / page title text, so injecting a<span>would corrupt the payload.