Repository: phoenixframework/phoenix
Pull request #6189 (2025-04-11 13:10:15)

use data-phx-session as selector for LV containers
Closes https://github.com/phoenixframework/phoenix/issues/6188.

`[data-phx-session]` is more appropriate, since the session attribute is already included in the disconnected render.

JonRowe: Thanks! 🙏 

Patch:
diff --git a/installer/templates/phx_assets/app.css b/installer/templates/phx_assets/app.css
index 3ff6aabd2..b20471303 100644
--- a/installer/templates/phx_assets/app.css
+++ b/installer/templates/phx_assets/app.css
@@ -92,11 +92,11 @@
 }
 
 /* Add variants based on LiveView classes */
-@custom-variant phx-click-loading ([".phx-click-loading&", ".phx-click-loading &"]);
-@custom-variant phx-submit-loading ([".phx-submit-loading&", ".phx-submit-loading &"]);
-@custom-variant phx-change-loading ([".phx-change-loading&", ".phx-change-loading &"]);
+@custom-variant phx-click-loading (.phx-click-loading&, .phx-click-loading &);
+@custom-variant phx-submit-loading (.phx-submit-loading&, .phx-submit-loading &);
+@custom-variant phx-change-loading (.phx-change-loading&, .phx-change-loading &);
 
 /* Make LiveView wrapper divs transparent for layout */
-[data-phx-root-id] { display: contents }
+[data-phx-session] { display: contents }
 
 /* This file is for your main application CSS */
diff --git a/installer/templates/phx_static/default.css b/installer/templates/phx_static/default.css
index 66836523a..f78adc7ae 100644
--- a/installer/templates/phx_static/default.css
+++ b/installer/templates/phx_static/default.css
@@ -2288,7 +2288,7 @@
     }
   }
 }
-[data-phx-root-id] {
+[data-phx-session] {
   display: contents;
 }
 @layer base {
diff --git a/priv/templates/phx.gen.context/access_no_schema.ex b/priv/templates/phx.gen.context/access_no_schema.ex
index 66b765e91..e24173435 100644
--- a/priv/templates/phx.gen.context/access_no_schema.ex
+++ b/priv/templates/phx.gen.context/access_no_schema.ex
@@ -39,7 +39,7 @@
       {:error, ...}
 
   """
-  def create_<%= schema.singular %>(attrs \\ %{}) do
+  def create_<%= schema.singular %>(attrs) do
     raise "TODO"
   end
 
diff --git a/priv/templates/phx.gen.context/access_no_schema_scope.ex b/priv/templates/phx.gen.context/access_no_schema_scope.ex
index 2ad0eaabf..eef5d57b3 100644
--- a/priv/templates/phx.gen.context/access_no_schema_scope.ex
+++ b/priv/templates/phx.gen.context/access_no_schema_scope.ex
@@ -47,7 +47,7 @@
       {:error, ...}
 
   """
-  def create_<%= schema.singular %>(%<%= inspect scope.alias %>{} = _scope, attrs \\ %{}) do
+  def create_<%= schema.singular %>(%<%= inspect scope.alias %>{} = _scope, attrs) do
     raise "TODO"
   end
 
diff --git a/priv/templates/phx.gen.context/schema_access.ex b/priv/templates/phx.gen.context/schema_access.ex
index 9bedfd035..b55b1d9bc 100644
--- a/priv/templates/phx.gen.context/schema_access.ex
+++ b/priv/templates/phx.gen.context/schema_access.ex
@@ -42,7 +42,7 @@
       {:error, %Ecto.Changeset{}}
 
   """
-  def create_<%= schema.singular %>(attrs \\ %{}) do
+  def create_<%= schema.singular %>(attrs) do
     %<%= inspect schema.alias %>{}
     |> <%= inspect schema.alias %>.changeset(attrs)
     |> Repo.insert()
diff --git a/priv/templates/phx.gen.context/schema_access_scope.ex b/priv/templates/phx.gen.context/schema_access_scope.ex
index 5e4a71fc4..1f415317e 100644
--- a/priv/templates/phx.gen.context/schema_access_scope.ex
+++ b/priv/templates/phx.gen.context/schema_access_scope.ex
@@ -67,7 +67,7 @@
       {:error, %Ecto.Changeset{}}
 
   """
-  def create_<%= schema.singular %>(%<%= inspect scope.alias %>{} = scope, attrs \\ %{}) do
+  def create_<%= schema.singular %>(%<%= inspect scope.alias %>{} = scope, attrs) do
     with {:ok, <%= schema.singular %> = %<%= inspect schema.alias %>{}} <-
            %<%= inspect schema.alias %>{}
            |> <%= inspect schema.alias %>.changeset(attrs, scope)


Test patch:
diff --git a/test/mix/tasks/phx.gen.context_test.exs b/test/mix/tasks/phx.gen.context_test.exs
index fb55f5d8e..a018f4a42 100644
--- a/test/mix/tasks/phx.gen.context_test.exs
+++ b/test/mix/tasks/phx.gen.context_test.exs
@@ -494,7 +494,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do
             assert file =~ "def subscribe_posts(%Scope{} = scope)"
             assert file =~ "def get_post!(%Scope{} = scope, id)"
             assert file =~ "def list_posts(%Scope{} = scope)"
-            assert file =~ "def create_post(%Scope{} = scope, attrs \\\\ %{})"
+            assert file =~ "def create_post(%Scope{} = scope, attrs)"
             assert file =~ "def update_post(%Scope{} = scope, %Post{} = post, attrs)"
             assert file =~ "def delete_post(%Scope{} = scope, %Post{} = post)"
             assert file =~ "def change_post(%Scope{} = scope, %Post{} = post, attrs \\\\ %{})"