Live modal not showing flash messages

When I call put_flash on my socket, it shows flash messages in the regular area inside of live.html.heex. It does not show flash messages in the modal when I call put_flash with a modal showing. In the book I’m reading, the modal shows as looking like this:

Have there been some changes that removed flash messages from the default live modal? How can I get mine to look more like the book? I’m using the default .modal component.

 defp handle_progress(:image, entry, socket) do
    if entry.done? do
      path =
        consume_uploaded_entry(
          socket,
          entry,
          &upload_static_file(&1, socket)
        )

      {:noreply,
       socket
       |> put_flash(:info, "file #{entry.client_name} uploaded")
       |> assign(:image_upload, path)}
    else
      {:noreply, socket}
    end
  end
1 Like

The modal was changed from a LiveComponent to a function component in 1.6.3 and function components don’t use a separate @flash assign on put_flash/3.

Using something like

     {:noreply,
       socket
       |> assign(:flash, %{"info" => "file #{entry.client_name} uploaded"})
       |> assign(:image_upload, path)}

and then retrieving it in the template would probably be the easiest solution.
Under the hood the put_flash/3 / get_flash/2 calls do a similar thing.

1 Like