Below I inspect the socket in the parent LiveView and the child LiveView mount functions.
In LiveView, mount always runs twice (once before connected, once after connected).
# PARENT (parent mount)
%Phoenix.LiveView.Socket{
assigns: %{},
changed: %{},
connected?: false,
endpoint: JavelinWeb.Endpoint,
fingerprints: {nil, %{}},
id: "phx-k87LXud9",
parent_pid: nil,
private: %{
assigned_new: {%{
current_user: %Javelin.Users.User{
__meta__: #Ecto.Schema.Metadata<:built, "users">,
confirm_password: nil,
current_password: nil,
email: nil,
id: 231,
inserted_at: nil,
password: nil,
password_hash: nil,
updated_at: nil
}
}, []},
connect_params: %{}
},
redirected: nil,
router: JavelinWeb.Router,
view: JavelinWeb.ProjectLive
}
# PARENT (child mount)
%Phoenix.LiveView.Socket{
assigns: %{current_user_id: 231, name: "Pedro Jones", users: []},
changed: %{current_user_id: true, name: true, users: true},
connected?: false,
endpoint: JavelinWeb.Endpoint,
fingerprints: {nil, %{}},
id: "phx-k87LXud9",
parent_pid: nil,
private: %{
assigned_new: {%{
current_user: %Javelin.Users.User{
__meta__: #Ecto.Schema.Metadata<:built, "users">,
confirm_password: nil,
current_password: nil,
email: nil,
id: 231,
inserted_at: nil,
password: nil,
password_hash: nil,
updated_at: nil
}
}, []},
connect_params: %{}
},
redirected: nil,
router: JavelinWeb.Router,
view: JavelinWeb.ProjectLive
}
# CHILD (child mount)
%Phoenix.LiveView.Socket{
assigns: %{},
changed: %{},
connected?: false,
endpoint: JavelinWeb.Endpoint,
fingerprints: {nil, %{}},
id: "phx-k87LXud9JavelinWeb.DiscoveryCategoriesLive",
parent_pid: #PID<0.733.0>,
private: %{
assigned_new: {%{current_user_id: 231, name: "Pedro Jones", users: []}, []},
connect_params: %{}
},
redirected: nil,
router: JavelinWeb.Router,
view: nil
}
[info] Sent 200 in 1ms
[info] CONNECTED TO Phoenix.LiveView.Socket in 211µs
Transport: :websocket
Serializer: Phoenix.Socket.V2.JSONSerializer
Connect Info: %{}
Parameters: %{"vsn" => "2.0.0"}
## START SECOND GO AROUND
# PARENT (parent mount)
%Phoenix.LiveView.Socket{
assigns: %{},
changed: %{},
connected?: true,
endpoint: JavelinWeb.Endpoint,
fingerprints: {nil, %{}},
id: "phx-k87LXud9",
parent_pid: nil,
private: %{assigned_new: {%{}, []}, connect_params: %{}},
redirected: nil,
router: JavelinWeb.Router,
view: JavelinWeb.ProjectLive
}
# PARENT (child mount)
%Phoenix.LiveView.Socket{
assigns: %{},
changed: %{current_user_id: true, name: true, users: true},
connected?: true,
endpoint: JavelinWeb.Endpoint,
fingerprints: {nil, %{}},
id: "phx-k87LXud9",
parent_pid: nil,
private: %{connect_params: %{}},
redirected: nil,
router: JavelinWeb.Router,
view: JavelinWeb.ProjectLive
}
# CHILD (child mount)
%Phoenix.LiveView.Socket{
assigns: %{},
changed: %{},
connected?: true,
endpoint: JavelinWeb.Endpoint,
fingerprints: {nil, %{}},
id: "phx-k87LXud9JavelinWeb.DiscoveryCategoriesLive",
parent_pid: #PID<0.753.0>,
private: %{assigned_new: {%{}, []}, connect_params: %{}},
redirected: nil,
router: JavelinWeb.Router,
view: JavelinWeb.DiscoveryCategoriesLive
}
I noticed two weird things.
-
The parent socket in the child mount. The first time it changes all the values in assigns to true for some reason. The second time the assigns is empty but again it has the changes with all the values set to true.
-
The ID of the child socket is basically the same ID as the parent but with the name of the module attached “phx-k87LXud9JavelinWeb.DiscoveryCategoriesLive”
Is this the intended behavior?