PhoenixWebTransport.LaneSerializer (phoenix_wtransport v0.1.0)

Copy Markdown View Source

A Phoenix.Socket.Serializer that splits one LiveView diff push into several independently deliverable frames, one per updated component.

The wire format of every frame is identical to the V2 JSON serializer, so the browser side needs no changes beyond delivering frames from several streams into the same phoenix.js socket. What changes is the packaging: instead of one {:socket_push, :text, json} this serializer returns

{:socket_push, :binary, <<"L", count::16, (lane::32, len::32, json)*>>}

and the transport maps each lane onto its own QUIC stream.

Which parts of a diff may travel alone

A component diff in c that carries no s (statics) key is a pure delta to a component the client already knows. It depends on nothing else in the same message, so it goes on lane cid.

Everything else stays together on lane 0 (the control lane): the root diff, new or reset components (they carry s and the root usually references them), components that share statics with a sibling in the same diff (s is a positive cid), events, title, replies, joins and heartbeats. Lane 0 is also where all messages of other serializers' shape go, so a socket that never renders components behaves exactly like WebSocket.

Summary

Functions

Splits a diff payload into {control_payload, [{cid, component_diff}]}.

Functions

split_components(payload)

Splits a diff payload into {control_payload, [{cid, component_diff}]}.

Exposed for tests and for the spec; see the moduledoc for the rule.