File upload works only every other time

Hello,

I’m a bit stuck with a problem that doesn’t seem to go away no matter what I try. I tried it with different liveview versions, including 1.0.0-rc.5, but no dice.

Basically I have a small app for uploading images to a digital album (example album: Albums Digital). Each album has multiple pages and each page has its own upload form.

Now most of the time the uploads work fine, but it seems every other time or so it gets stuck and the backend receives no events. I even tried to check for change events on the client side, but they seem not be fired at all in that case.
The relevant code can be found here Upload code · GitHub

Feel free to create a user to try it out. But I’m a bit at a loss why this is happening, so any suggestions or pointers would be appreciated.

Steps to reproduce: create a new album, upload a few images (either via link at bottom of page or drag&drop). Page ahead, repeat and notice that sometimes you select some images, but no upload was triggered. Immediately after a failure the upload works again.

I suspect there is something off with the state of the form or something like that, I’m also very new to Phoenix and Elixir so maybe I did some silly mistake somewhere.

Cheers,
Andreas

Ok I tracked this down some more and it was caused by using custom flash code I found somewhere:

defmodule AlbumWeb.Flash do
  import Phoenix.LiveView

  require Logger

  def on_mount(:default, _params, _session, socket) do
    {:cont, attach_hook(socket, :flash_receiver, :handle_info, &maybe_receive_flash/2)}
  end

  defp maybe_receive_flash({:put_flash, type, message}, socket) do
    {:halt, put_flash(socket, type, message)}
  end

  defp maybe_receive_flash(_, socket), do: {:cont, socket}

  def put_flash!(socket, type, message) do
    send(self(), {:put_flash, type, message})
    Process.send_after(self(), :clear_flash, 3000)
    socket
  end
end

Somehow calling put_flash!() was breaking the state. I have for now opted to not use flash during an upload.

sorry, I thought my previous update fixed it, but my problem still persists.