lv:assigns

LiveView Assigns Audit

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "lv:assigns" with this command: npx skills add oliver-kriska/claude-elixir-phoenix/oliver-kriska-claude-elixir-phoenix-lv-assigns

LiveView Assigns Audit

Analyze LiveView socket assigns for memory efficiency, clarity, and best practices.

Iron Laws - Never Violate These

  • Use streams for lists > 100 items - Never store large lists directly in assigns

  • Use temporary_assigns for transient data - Flash messages, temp errors, notifications

  • Preload only needed fields - Don't store full Ecto schemas when only needing subset

  • Initialize all assigns in mount - Never access assigns that might not exist

Quick Audit Commands

Extract All Assigns

grep -E "assign(|assign_new(" path/to/live_view.ex

Find Large Data Patterns

Lists stored in assigns

grep -E "assign.*[]|assign.*Repo.all" path/to/live_view.ex

Full schema storage

grep -E "assign.Repo.get|assign.%.*{}" path/to/live_view.ex

Audit Checklist

  1. Memory Issues

Pattern Problem Solution

assign(:items, Repo.all(...))

Unbounded list Use stream/3

assign(:user, Repo.get!(...))

Full schema Select only needed fields

assign(:file_data, binary)

Large binary Store reference, not data

Nested preloads Excessive data Preload only what's rendered

  1. Missing temporary_assigns

Should use temporary_assigns :

  • Flash messages

  • Form errors after submission

  • One-time notifications

  • Upload progress

def mount(_params, _session, socket) do {:ok, socket, temporary_assigns: [flash_message: nil]} end

  1. Unused Assigns

Search for assigns defined but never used in templates:

Find assigns

grep -oE "assign(:(\w+)" live_view.ex | sort -u

Compare with template usage

grep -oE "@\w+" template.html.heex | sort -u

  1. Missing Initialization

BAD: @items might not exist

def render(assigns) do ~H"<%= for item <- @items do %>" end

GOOD: Initialize in mount

def mount(_params, _session, socket) do {:ok, assign(socket, items: [])} end

Memory Estimation

For each assign, estimate memory footprint:

Data Type Approx Size Concern Level

Integer 8 bytes Low

String (100 chars) ~200 bytes Low

List of 100 maps ~10-50 KB Medium

List of 1000 items ~100-500 KB High

Binary (image) Varies Critical

Full Ecto schema ~1-5 KB each Medium

Usage

Run /lv:assigns path/to/live_view.ex to generate an assigns inventory with memory estimates and optimization recommendations.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Security

security

No summary provided by upstream source.

Repository SourceNeeds Review
Security

phx:audit

No summary provided by upstream source.

Repository SourceNeeds Review
General

oban

No summary provided by upstream source.

Repository SourceNeeds Review