LiveVue minimizes WebSocket payload sizes by tracking only modified props, slots, and handlers. For complex data structures, you can implement the LiveVue.Encoder protocol to enable efficient diffing. By converting structs to consistent map representations, LiveVue can calculate minimal JSON patches (using Jsonpatch) instead of re-sending entire objects.
When a field changes, LiveVue sends a JSON patch operation (e.g., replace) rather than the full struct, which reduces payload size and improves client-side rendering performance.
# For complex types, use Jsonpatch to find minimal diff
old_value ->
old_value
|> Encoder.encode()
|> Jsonpatch.diff(new_value)
|> update_in([Access.all(), :path], fn path -> "/#{k}#{path}" end)
Example of a patch instead of a full struct:
Instead of sending the entire user struct:
%{user: %{name: "John", email: "new@example.com", created_at: ~U[...]}}
LiveVue sends only the changed field:
[%{op: "replace", path: "/user/email", value: "new@example.com"}]