Rbtz.CredoChecks.Warning.PhxUpdateStreamWithoutId (rbtz_credo_checks v0.2.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Requires every element with phx-update="stream" to also carry an id attribute.

LiveView streams key children by DOM id. Without a stable id on the stream container, LiveView cannot diff the inserted/removed items across patches — items disappear, duplicate, or land in the wrong position. The framework raises at runtime if the id is missing, but a static check catches the mistake at code-review time.

The check inspects every ~H sigil and every .heex template referenced via embed_templates. It walks each opening tag (across multiple lines) and flags those that carry phx-update="stream" without id=.

Bad

<div phx-update="stream">
  <div :for={{dom_id, msg} <- @streams.messages} id={dom_id}>...</div>
</div>

Good

<div id="messages" phx-update="stream">
  <div :for={{dom_id, msg} <- @streams.messages} id={dom_id}>...</div>
</div>

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.