Update LiveView 0.11.1 . Error occurring in :flash

After I update to the most recent version, my event of opening a modal is no longer responding, it gives me the error " : flash is a reserved assign by LiveView and it cannot be set directly. Use the appropriate flash functions instead". Is anyone having the same problem? If yes, help me to solve :smile:

Use put_flash.

Raise if :flash is given as an assign was introduced in 0.9.0.


I’m already using put_flash in my occurrences, this is the weird thing :frowning_face:

For example, this is my event called the modal. Before the Live View update, it was working properly, but now he doesn’t want to respond anymore.

  def handle_event("open_modal", %{"modal_btn_id" => modal_btn_id}, socket) do
    contato = Entities.get_contato!(modal_btn_id)

       to: Routes.live_path(socket, BoardLive, socket.assigns.slug, contato.slug),
       replace: false

On what LiveView version were you before the upgrade?

Check if you are re-assigning the assigns from the socket (which would have the :flash in it) anywhere in the code. In this case search for occurrences like this: assign(socket, assigns) .

1 Like

I was using liveview 0.8.1.
When I check the output of my socket that is being fixed in “def mount” it returns a flash: %{}, like this:

Phoenix.LiveView.Socket <
  assigns:% {flash:% {}, live_action: nil, live_module: FluxoIdealWeb.BoardLive},
  changed:% {},

When I click to open the modal, the flash error indicates that it is occurring in this line of my code.

 {:ok, assign(socket, Map.merge(@defaults, assigns))}
  def render(assigns) do
    BoardView.render("modal.html", assigns)

  def mount(params, _session, socket) do
    {:ok, socket}

  def update(
          id: id,
          tag_actions_y: tag_actions_y,
          tag_actions_x: tag_actions_x,
          tags: tags,
          all_tags: all_tags,
          dashboard: dashboard,
          format_date_now_string: format_date_now_string
        } = assigns,
      ) do
    {:ok, assign(socket, Map.merge(@defaults, assigns))}

I found the error, I was passing a @flash as reference for my ModalComponent, now everything is working :smile: . Thank you !!

1 Like