Soundcheck.Check.Warning.StreamContainerWithoutPhxUpdate (soundcheck v0.1.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

Flags elements that loop over a stream whose parent lacks phx-update="stream". Without it, LiveView replaces the container's children on every update instead of inserting and deleting stream items, so items disappear. LiveView reports this only in the browser, in debug mode.

Before:

<ul id="posts">
  <li :for={{id, post} <- @streams.posts} id={id}>{post.title}</li>
</ul>

After:

<ul id="posts" phx-update="stream">
  <li :for={{id, post} <- @streams.posts} id={id}>{post.title}</li>
</ul>

Loops whose parent is a component or slot, or that sit at the template root, are skipped: the container is rendered elsewhere.

Confidence: high. Tier: syntactic (works without compiling).

Check-Specific Parameters

Use the following parameters to configure this check:

:excluded_paths

Paths to skip (atoms, binaries as path segments, or regexes).

This parameter defaults to [~r/\/test\//, "test"].

:strict

Unused.

This parameter defaults to false.

General Parameters

Like with all checks, general params can be applied.

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