michelson
Upgraded to 1.7 live view 0.18, I’m getting odd behavior with put_flash
Hi there:
I have upgraded to 1.7 live view 0.18, I’m getting this odd behavior with put_flash, and suddenly this:
{:noreply,
socket
|> put_flash(:info, "Event created successfully")
|> push_redirect(to: "/events/#{event.slug}/edit")}
Does not put any flash, by the other hand if I don’t do the redirect, it works.
Also in some Live Components, I have changed the push_redirect to push_navigate, in some cases works, in others don’t. I have realized this because I have some integration tests that failed, but I have not 100% coverage and I assume that my app now is completely broken by this API change ![]()
Marked As Solved
josevalim
Can you please confirm that you have also updated the LiveView JS client from npm when you updated the server to v0.18? Otherwise they may indeed not work if they are mismatched.
Also Liked
codeanpeace
The put_flash/3 docs include the following notes that seem relevant:
Note: While you can use
put_flash/3inside aPhoenix.LiveComponent, components have their own@flashassigns. The@flashassign in a component is only copied to its parent LiveView if the component callspush_navigate/2orpush_patch/2.Note: You must also place the
Phoenix.LiveView.Router.fetch_live_flash/2plug in your browser’s pipeline in place offetch_flashfor LiveView flash messages be supported, for example:
import Phoenix.LiveView.Router
pipeline :browser do
...
plug :fetch_live_flash
end
josevalim
For the modal that does not work, what happens is that when you submit the form, it crashes the component and the live view, because you are expecting a “ticket_id” parameter but none is submitted. You should see reports that the LiveView crashed both in your browser console (run liveSocket.enableDebug() once) and your app console.
If I change the handle_event to this:
def handle_event("save", %{"invite_ticket_form" => _}, socket) do
{:noreply,
socket
|> assign(:open_modal, false)
|> assign(:status, :success)
|> put_flash(:info, gettext("Invitation sent"))
|> push_redirect(to: "/events/#{socket.assigns.event.slug}/edit/attendees")}
end
Then it works for me (in that the flash shows).
michelson
oh, I think you were right! there was an error and I didn’t see it. I will be do some tests tomorrow but I think the mistery is solved
Last Post!
michelson
oh! you are right
I’ve upgraded this:
- "phoenix": "^1.6.10",
- "phoenix_html": "^3.2.0",
- "phoenix_live_view": "^0.17.10",
+ "phoenix": "^1.7.1",
+ "phoenix_html": "^3.3.1",
+ "phoenix_live_view": "^0.18.17",
And it seems to be working now!
thank you all who help me with this, thank you thank you than you.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









