LiveView's Reactive State: AI's Common Fails
AGENT.md corrects AI's frequent missteps in Phoenix LiveView, specifically addressing incorrect `handle_event` implementations and inefficient or flawed state management via `assigns` updates.
The top 3
- Top AI Fails: Over-assigning LiveView State: AI often overloads LiveView's socket `assigns` with excessive data, like entire Ecto structs, leading to significant memory bloat and poor UI diff performance. It frequently misses opportunities to use `temporary_assigns` for transient values, which is a key optimization for reactive state.
- AI's Struggle: LiveView Callback Misuse: AI code generators frequently misapply LiveView's crucial callbacks—`mount`, `handle_params`, `handle_event`, and `handle_info`—resulting in incorrect state updates, unexpected UI behavior, or logic errors due to a misunderstanding of the reactive lifecycle stages.
- Common AI Pitfall: Inconsistent Component State: AI-generated LiveView code often leads to duplicated or inconsistent state across parent LiveViews and nested LiveComponents, struggling with effective state synchronization and frequently resorting to inefficient 'prop drilling' rather than robust shared state patterns.
Sources
Open the full topic