Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Installation: don't crash when socket reconnects and finds no changes (#4520)

hq1acefd792fb29
diff --git a/lib/plausible_web/live/installation.ex b/lib/plausible_web/live/installation.ex
index a28b03b816..4a1147b2c7 100644
--- a/lib/plausible_web/live/installation.ex
+++ b/lib/plausible_web/live/installation.ex
@@ -400,8 +400,15 @@ defmodule PlausibleWeb.Live.Installation do
flash = snippet_change_flash(socket.assigns.script_config, new_params)
+ socket =
+ if flash do
+ put_live_flash(socket, :success, flash)
+ else
+ socket
+ end
+
socket = update_uri_params(socket, new_params)
- {:noreply, put_live_flash(socket, :success, flash)}
+ {:noreply, socket}
end
def handle_params(params, _uri, socket) do
@@ -518,13 +525,14 @@ defmodule PlausibleWeb.Live.Installation do
defp snippet_change_flash(old_config, new_config) do
change =
- Enum.find(new_config, fn {key, value} ->
- if old_config[key] != new_config[key] do
- {key, value}
- end
+ Enum.find(new_config, fn {key, _value} ->
+ old_config[key] != new_config[key]
end)
case change do
+ nil ->
+ nil
+
{k, false} when k in ["outbound-links", "file-downloads", "404"] ->
"Snippet updated and goal deleted. Please insert the newest snippet into your site"
diff --git a/test/plausible_web/live/installation_test.exs b/test/plausible_web/live/installation_test.exs
index c2dbccb8cc..c35d73a26a 100644
--- a/test/plausible_web/live/installation_test.exs
+++ b/test/plausible_web/live/installation_test.exs
@@ -326,6 +326,20 @@ defmodule PlausibleWeb.Live.InstallationTest do
assert render(lv) =~ "Snippet updated. Please insert the newest snippet into your site"
end
+
+ test "no changes", %{conn: conn, site: site} do
+ {lv, _html} = get_lv(conn, site, "?installation_type=manual")
+
+ lv
+ |> element(~s|form#snippet-form|)
+ |> render_change(%{})
+
+ lv
+ |> element(~s|form#snippet-form|)
+ |> render_change(%{})
+
+ refute render(lv) =~ "Snippet updated"
+ end
end
defp stub_fetch_body(f) when is_function(f, 1) do