Freezing After Controller Redirect

I am currently working on downloading an HTML table to a csv file. I have a button that fires a “download” event. Captured here:

def handle_event("download", _params, %{assigns: %{epics: epics}} = socket) do
    {:noreply, download_to_csv(epics, socket)}

The data and socket it passed to a private function I use to format everything properly for the csv file. Everything with file format seems to be fine. The file downloads and looks the way I want it to. My issue is that the liveview then seems to freeze(?). The progress bar just slowly creeps across the page and never actually completes.

Here is the redirect to the ExportController

      to: Routes.export_path(socket, :index, filename, csv_data: content)

… and here is the ExportController

def index(conn, %{"csv_data" => csv_data, "filename" => filename}) do
    content_size = csv_data |> :erlang.term_to_binary() |> byte_size()

    |> put_resp_content_type("application/csv")
    |> put_resp_header("content-disposition", "attachment; filename=#{filename}")
    |> put_resp_header("content-size", "#{content_size}")
    |> put_root_layout(false)
    |> send_resp(200, csv_data)

There are no error messages indicating a hiccup anywhere, I am stumped…

I’d strongly suggest not sending a whole csv as a GET parameter.

  1. The URL is passed to the client, then the browser redirects and then the browser downloads the file (again essentially)
  2. GET parameters are limited in size and I’m not sure how browsers act if they get a redirect, which exceeds those limits.

so pass the items to be formatted in the csv as a param to the controller and then format the file for download in a private function within the controller?