Skip to content

Commit 43b9333

Browse files
committed
fix existing tests
1 parent f13ff3a commit 43b9333

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

lib/phoenix_live_view/channel.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ defmodule Phoenix.LiveView.Channel do
476476

477477
Process.send_after(self(), {@prefix, :adoption_timeout}, timeout)
478478

479-
{:reply, {:ok, Diff.to_iodata(diff)}, {:adoptable, state}}
479+
# TODO: check if we can avoid sending the assigns back
480+
{:reply, {:ok, Diff.to_iodata(diff), socket.assigns}, {:adoptable, state}}
480481

481482
{:stop, socket} ->
482483
{:stop, :shutdown, {:stop, socket}, nil}
@@ -1100,7 +1101,13 @@ defmodule Phoenix.LiveView.Channel do
11001101
new_socket = Utils.clear_temp(socket)
11011102

11021103
{:diff, diff,
1103-
%{state | socket: new_socket, fingerprints: fingerprints, components: components, initial_diff: nil}}
1104+
%{
1105+
state
1106+
| socket: new_socket,
1107+
fingerprints: fingerprints,
1108+
components: components,
1109+
initial_diff: nil
1110+
}}
11041111
end
11051112

11061113
defp reply(state, {ref, extra}, status, payload) do

lib/phoenix_live_view/controller.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ defmodule Phoenix.LiveView.Controller do
3737
"""
3838
def live_render(%Plug.Conn{} = conn, view, opts \\ []) do
3939
case LiveView.Static.render(conn, view, opts) do
40-
{:ok, content} ->
40+
{:ok, content, socket_assigns} ->
4141
conn
4242
|> Plug.Conn.fetch_query_params()
4343
|> ensure_format()
4444
|> Phoenix.Controller.put_view(LiveView.Static)
4545
|> Phoenix.Controller.render(
4646
:template,
47-
%{content: content}
47+
Map.merge(socket_assigns, %{content: content, live_module: view})
4848
)
4949

5050
{:stop, %Socket{redirected: {:redirect, %{status: status} = opts}} = socket} ->

lib/phoenix_live_view/static.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ defmodule Phoenix.LiveView.Static do
174174
]
175175

176176
try do
177-
{:ok, to_rendered_content_tag(socket, tag, view, attrs)}
177+
{:ok, to_rendered_content_tag(socket, tag, view, attrs), socket.assigns}
178178
catch
179179
:throw, {:phoenix, :child_redirect, redirected, flash} ->
180180
{:stop, Utils.replace_flash(%{socket | redirected: redirected}, flash)}
@@ -210,7 +210,8 @@ defmodule Phoenix.LiveView.Static do
210210
)
211211

212212
# TODO: handle call timeout
213-
with {:ok, iodata} <- GenServer.call(pid, {:phoenix, :disconnected_adoptable_render}) do
213+
with {:ok, iodata, assigns} <-
214+
GenServer.call(pid, {:phoenix, :disconnected_adoptable_render}) do
214215
data_attrs = [
215216
phx_session: sign_root_session(socket, router, view, to_sign_session, live_session),
216217
phx_static: sign_static_token(socket),
@@ -225,7 +226,9 @@ defmodule Phoenix.LiveView.Static do
225226
| extended_attrs
226227
]
227228

228-
{:ok, content_tag(tag, attrs, iodata)}
229+
# TODO: we currently expect the socket assigns for LiveViewTest
230+
# check if we can aboid copying assigns...
231+
{:ok, content_tag(tag, attrs, iodata), assigns}
229232
end
230233
end
231234
end

0 commit comments

Comments
 (0)