PhoenixReplay.Capture.AsyncResults (PhoenixReplay v0.6.2)

Copy Markdown View Source

Records LiveComponent state changed by async results.

LiveView emits no telemetry when a start_async/3, assign_async/3 or stream_async/4 result is applied to a LiveComponent, and the render that follows clears the component's change tracking, so PhoenixReplay.Capture.LiveComponents never sees that state.

This is a workaround until LiveView emits [:phoenix, :live_component, :handle_async, :stop], proposed in https://github.com/phoenixframework/phoenix_live_view/pull/4463. Once it does, PhoenixReplay.Capture.LiveComponents records async results from that event, every component render is explained, and this module stops firing.

A component render that no recorded event explains is taken to be an async result. A supervised task then reads the component's assigns with Phoenix.LiveView.Debug.live_components/1, which cannot be called from the LiveView process itself, and records them as a :component event. The snapshot reflects the component once the LiveView handles the request, which may include changes from messages queued behind the render, and its offset is the time it is recorded.

Summary

Functions

Notes that the next render of the component is caused by an event that was recorded. Called from the LiveView process.

Handles a component render in the LiveView process, snapshotting the component when no recorded event explains it.

Records the current assigns of the component cid rendered by pid.

Functions

explain(arg1)

@spec explain(Phoenix.LiveView.Socket.t()) :: :ok

Notes that the next render of the component is caused by an event that was recorded. Called from the LiveView process.

LiveView renders a component after an event exactly when the event left its socket changed, so a note is set only then and is always consumed by that render.

rendered(module, id, cid)

@spec rendered(module(), term(), pos_integer()) :: :ok

Handles a component render in the LiveView process, snapshotting the component when no recorded event explains it.

snapshot(pid, module, id, cid)

@spec snapshot(pid(), module(), term(), pos_integer()) :: :ok | :error

Records the current assigns of the component cid rendered by pid.