Fix ArgumentError when a host LiveView uses stream/3 by dropping reserved assigns at every field-component spread site#1979
Merged
Flo0807 merged 1 commit intoMay 12, 2026
Conversation
Backpex spreads the parent LiveView's assigns into child field LiveComponents after dropping a hand-maintained key list. That list omitted `:streams` everywhere, and `:uploads` / `:myself` at three of the six call sites. When a host LiveView called `stream/3` (or `allow_upload/3`), the reserved key flowed into the child and `Phoenix.Component.assign/3` raised `ArgumentError` from any field whose `update/2` does `assign(assigns)` -- `BelongsTo`, `HasMany`, `HasManyThrough`, `MultiSelect`, `InlineCRUD`. Centralize the reserved-key set as `Backpex.HTML.Resource.lv_reserved_assigns/0` and route every spread site through it. Site-specific extras (`:fields`) are prepended.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash when a host LiveView uses stream/3 (or uploads) by ensuring Backpex never forwards LiveView-reserved assigns (e.g. :streams, :uploads, :myself) when spreading parent assigns into child LiveComponents.
Changes:
- Centralizes the LiveView-reserved assign keys in
Backpex.HTML.Resource.lv_reserved_assigns/0. - Updates all documented assign-spread sites to drop the centralized reserved set (plus site-specific keys like
:fields). - Adds tests verifying the reserved set includes
:streamsand that dropping it removes:streamsfrom a parent-style assigns map.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/backpex/html/resource.ex |
Adds lv_reserved_assigns/0 and routes multiple LiveComponent assign spreads through it. |
lib/backpex/html/item_action.ex |
Drops the centralized reserved assigns (plus :fields) when spreading assigns into the modal form component. |
lib/backpex/html/resource/resource_index.html.heex |
Drops reserved assigns (plus :fields) when spreading assigns into the resource-action modal component. |
lib/backpex/html/resource/resource_form_main.html.heex |
Drops reserved assigns when spreading assigns into the main form component. |
test/backpex/html/resource_test.exs |
Adds coverage for the reserved-assign helper and for dropping :streams. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backpex spreads the parent LiveView's
assignsinto child field LiveComponents after dropping a hand-maintained list of keys. That list was missing:streamseverywhere, and:uploads/:myselfat three of the six sites. When a host LiveView callsstream(socket, :name, [])(orallow_upload/3), the reserved key flows into the child andPhoenix.Component.assign/3raises:This affects every field whose
update/2doessocket |> assign(assigns):BelongsTo,HasMany,HasManyThrough,MultiSelect,InlineCRUD.Changes
Backpex.HTML.Resource.lv_reserved_assigns/0returning[:flash, :uploads, :streams, :socket, :myself]— the full set rejected byPhoenix.Component.assign/3(plus:flash, which was already dropped at every site).Map.drop(assigns, ...)spread sites through the new helper:lib/backpex/html/resource.ex(3 sites:live_resource_field/1,inlined_resource_field/1,resource_form_field/1)lib/backpex/html/item_action.ex(1 site)lib/backpex/html/resource/resource_form_main.html.heex(1 site)lib/backpex/html/resource/resource_index.html.heex(1 site)Site-specific extras (
:fields) are prepended with[:fields | lv_reserved_assigns()].test/backpex/html/resource_test.exsasserting the helper returns the full reserved set and that dropping it removes:streamsfrom a parent-style assigns map.No version bump in this PR — will be handled separately when the release is cut.
Test plan
mix formatmix lint(compile / credo / 95 doctests + 166 tests, 0 failures)mix test test/backpex/html/resource_test.exs— 2/2 passstream/3on mount and renders aBelongsTofield — page renders withoutArgumentError