michelson

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 :frowning:

Marked As Solved

josevalim

josevalim

Creator of Elixir

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

codeanpeace

The put_flash/3 docs include the following notes that seem relevant:

Note: While you can use put_flash/3 inside a Phoenix.LiveComponent, components have their own @flash assigns. The @flash assign in a component is only copied to its parent LiveView if the component calls push_navigate/2 or push_patch/2.

Note: You must also place the Phoenix.LiveView.Router.fetch_live_flash/2 plug in your browser’s pipeline in place of fetch_flash for LiveView flash messages be supported, for example:

import Phoenix.LiveView.Router

pipeline :browser do
  ...
  plug :fetch_live_flash
end
josevalim

josevalim

Creator of Elixir

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

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

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.

Where Next?

Popular in Questions Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement