Skip to content

fix: keep the flash map intact in the put_toast sync path - #82

Open
churcho wants to merge 1 commit into
srcrip:mainfrom
churcho:fix/put-toast-sync-flash-map
Open

churcho wants to merge 1 commit into
srcrip:mainfrom
churcho:fix/put-toast-sync-flash-map

Conversation

@churcho

@churcho churcho commented Sep 11, 2026

Copy link
Copy Markdown

When put_toast(socket, :success, "Saved") is followed by put_flash(socket, :error, "Check the form") before the client clears the success flash, the error flash does not render. The sync branch stores the whole assigns map under :f because the nested put_in expression returns the root map.

Use Map.put(assigns[:f], sync_toast_kind, nil) to update the flash map. The error flash now renders. The success message remains a stream toast, and its duplicate flash stays hidden. The tests also check the exact component flash map and one clear-flash event per matching update.

The change touches only lib/live_toast/live_component.ex, demo/test/demo_web/live/send_toast_test.exs, and CHANGELOG.md. Stream insertion, toast counts, dismissal, the public API, and JavaScript remain unchanged.

Check Result
Regression file before the fix, on the implementation from main at 1ef5300 16/18 passed; the two new tests failed; exit 2
cd demo && mix test test/demo_web/live/send_toast_test.exs after the fix 18 passed; exit 0
cd demo && mix test 32 passed; exit 0
mix format --check-formatted Exit 0
mix credo --strict at repository root Exit 0
cd demo && mix credo --strict test/demo_web/live/send_toast_test.exs Exit 0
git diff --check Exit 0

Before the fix, the regression output included:

test LiveToast.put_toast/4 renders another flash while the synced flash awaits client clearing
Expected truthy, got false
code: assert has_element?(view, "#flash-error", "Check the form")

test LiveToast.put_toast/4 keeps the component flash map flat when removing a synced flash
Assertion with == failed
code: assert socket.assigns.f == %{"success" => nil, "error" => "Check the form"}

Result: 16/18 passed
Failed: 2 tests

After the fix:

Result: 18 passed

Full suite:

Result: 32 passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant