Lavash.Optimistic.RenderWrapper (Lavash v0.4.0-rc.4)

Copy Markdown View Source

Layer-4 render wrapper: wraps the user's render output in a <div phx-hook="LavashOptimistic" ...> carrying the optimistic state JSON, version, and URL-field hints the JS client uses to hydrate.

Originally Lavash.LiveView.Runtime.wrap_render/3 (layer 1); relocated per docs/ARCHITECTURE.md punchlist item #8 so a layer-2-only build can skip the wrap entirely.

How it gets invoked

Lavash.LiveView.Transformers.CompileLiveView emits a render/1 whose tail invokes Lavash.LiveView.Runtime.wrap_render/3. That layer-1 function checks for this module via Code.ensure_loaded? + function_exported? and, if present, calls into wrap_render/3. Modules without the optimism extension fall through to inner_content unchanged.

What the wrapper produces

A Phoenix.LiveView.Rendered struct whose static parts are the wrapper div tags and whose dynamic parts include the user's inner content plus the serialized optimistic state. Fingerprint is structural only (module name + URL field list) so LiveView's diff machinery doesn't treat each render as a brand-new template.

Summary

Functions

wrap_render(module, assigns, inner_content)