From ea0c41ef50c375d9a2f3b64e2fdcaea2f6caa4ab Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 10 Apr 2026 14:04:16 -0500 Subject: [PATCH] Fix crash on /submit when LiveStash restores CSV tab without csv_result assign Set all assigns before LiveStash recovery so reconnecting to the CSV tab doesn't crash on missing :csv_result / :csv_preview keys. --- lib/microwaveprop_web/live/submit_live.ex | 30 ++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/microwaveprop_web/live/submit_live.ex b/lib/microwaveprop_web/live/submit_live.ex index 3ae3c778..df144e55 100644 --- a/lib/microwaveprop_web/live/submit_live.ex +++ b/lib/microwaveprop_web/live/submit_live.ex @@ -17,25 +17,27 @@ defmodule MicrowavepropWeb.SubmitLive do def mount(_params, _session, socket) do socket = allow_upload(socket, :csv, accept: ~w(.csv), max_entries: 1, max_file_size: 10_000_000) + changeset = Radio.change_contact(%Contact{}) + + socket = + assign(socket, + page_title: "Submit Contact", + form: to_form(changeset), + band_options: @band_options, + mode_options: @mode_options, + submitted_at: nil, + active_tab: :single, + csv_preview: nil, + csv_result: nil, + csv_email: "" + ) + case LiveStash.recover_state(socket) do {:recovered, socket} -> {:ok, socket} _ -> - changeset = Radio.change_contact(%Contact{}) - - {:ok, - assign(socket, - page_title: "Submit Contact", - form: to_form(changeset), - band_options: @band_options, - mode_options: @mode_options, - submitted_at: nil, - active_tab: :single, - csv_preview: nil, - csv_result: nil, - csv_email: "" - )} + {:ok, socket} end end