
Liveview Patterns
Build LiveView: async data (assign_async), PubSub (check connected?), phx-change...
Install
npx skills add oliver-kriska/claude-elixir-phoenix --skill liveview-patterns -g -a claude-code -y- Repository
- oliver-kriska/claude-elixir-phoenix572
- Category
- Testing
- Updated
- 5d ago
- License
- MIT
- Context cost
- Lightabout 1,232 tokens
- Runs scripts
- No, instructions only
What it does
Build LiveView: async data (assign_async), PubSub (check connected?), phx-change events, form components/modals/uploads, streams for lists, live_patch. Use when handling interactions, debugging events, or tracking Presence.
LiveView Patterns Reference
Ash projects: Use
ash-frameworkskill forAshPhoenix.Form. Lifecycle:AshPhoenix.Form.validate/3onphx-change,AshPhoenix.Form.submit/2on submit,to_form/1for HEEx. Do not useEcto.Changeset.cast/3.
Reference for building with Phoenix LiveView 1.0/1.1.
Iron Laws, Never Violate These
- NO UNCONDITIONAL DB QUERIES IN MOUNT, Mount runs TWICE. Default:
assign_async. SEO routes:connected?guard + cache-backed disconnected branch (crawlers read that HTML) - ALWAYS USE STREAMS FOR LISTS, Regular assigns = O(n) memory per user. Streams = O(1)
- CHECK connected?/1 BEFORE SUBSCRIPTIONS, Prevents double subscriptions
- EXTRACT VARIABLES BEFORE assign_async CLOSURE, Closures copy entire referenced variables
- LOAD PRIMARY DATA IN mount/3, PAGINATION IN handle_params/3, handle_params runs on EVERY URL change
- NEVER PASS SOCKET TO BUSINESS LOGIC, Extract data before calling contexts
- CHECK CHANGESET ERRORS BEFORE UI DEBUGGING, Silent form save = check
{:error, changeset}first, not viewport/JS - HIDDEN INPUTS FOR ALL REQUIRED EMBEDDED FIELDS, Every required field in an embedded schema MUST have a
hidden_inputif not directly editable - NEVER USE
assign_newFOR LIFECYCLE VALUES,assign_newskips the function if key exists. Useassign/3for locale, current user, or any value refreshed every mount - MATCH
{:error, %Ecto.Changeset{}}EXPLICITLY, Bare{:error, _}merges changeset and non-changeset errors; the form silently never re-renders validation errors. Handle other errors separately
Memory Impact
| Pattern | 3K items | 10K users × 10K items |
|---|---|---|
| Regular assigns | ~5.1 MB | ~10+ GB |
| Streams | ~1.1 MB | Minimal (O(1)) |
Decision: Lists with >100 items → Use streams, not assigns


