Skip to content

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

Don't preload goal settings modal to avoid issues with opening in edit mode (#5031)

Adrian Gruntkowski86f39196251e
diff --git a/lib/plausible_web/live/components/modal.ex b/lib/plausible_web/live/components/modal.ex
index 27d7404365..c0c7160c8a 100644
--- a/lib/plausible_web/live/components/modal.ex
+++ b/lib/plausible_web/live/components/modal.ex
@@ -101,6 +101,8 @@ defmodule PlausibleWeb.Live.Components.Modal do
"""
+ @test_preload_override? Mix.env() in [:test, :ce_test]
+
use PlausibleWeb, :live_component
alias Phoenix.LiveView
@@ -131,7 +133,11 @@ defmodule PlausibleWeb.Live.Components.Modal do
@impl true
def update(assigns, socket) do
- preload? = Map.get(assigns, :preload?, true)
+ # NOTE: This is a workaround for @test_preload_override? being computed
+ # at build time, where Mix.env() is available. Otherwise, dialyzer
+ # complains.
+ preload_override? = :erlang.phash2(1, 1) == 0 and @test_preload_override?
+ preload? = preload_override? || Map.get(assigns, :preload?, true)
socket =
assign(socket,
diff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.ex
index b2486a533a..c9162b702d 100644
--- a/lib/plausible_web/live/goal_settings.ex
+++ b/lib/plausible_web/live/goal_settings.ex
@@ -51,7 +51,7 @@ defmodule PlausibleWeb.Live.GoalSettings do
<div id="goal-settings-main">
<.flash_messages flash={@flash} />
- <.live_component :let={modal_unique_id} module={Modal} id="goals-form-modal">
+ <.live_component :let={modal_unique_id} module={Modal} preload?={false} id="goals-form-modal">
<.live_component
module={PlausibleWeb.Live.GoalSettings.Form}
id={"goals-form-#{modal_unique_id}"}
diff --git a/test/plausible_web/live/goal_settings_test.exs b/test/plausible_web/live/goal_settings_test.exs
index cdeb9e5190..06b986ead6 100644
--- a/test/plausible_web/live/goal_settings_test.exs
+++ b/test/plausible_web/live/goal_settings_test.exs
@@ -165,18 +165,6 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do
refute html =~ "No goals found for this site. Please refine or"
end
- test "Add Goal form view is rendered immediately, though hidden", %{conn: conn, site: site} do
- {:ok, _goals} = setup_goals(site)
- {_, html} = get_liveview(conn, site, with_html?: true)
-
- assert html =~ "Add Goal for #{site.domain}"
-
- assert element_exists?(
- html,
- ~s/#goals-form-modal form[phx-submit="save-goal"]/
- )
- end
-
test "auto-configuring custom event goals", %{conn: conn, site: site} do
populate_stats(site, [
build(:event, name: "Signup"),