Pass only the Livebook PID to child LiveViews (#2081)

This commit is contained in:
José Valim 2023-07-17 10:56:30 +02:00 committed by GitHub
parent 319ce562cb
commit 82909f7f35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 7 deletions

View file

@ -554,7 +554,7 @@ defmodule LivebookWeb.SessionLive do
<%= live_render(@socket, LivebookWeb.SessionLive.PackageSearchLive, <%= live_render(@socket, LivebookWeb.SessionLive.PackageSearchLive,
id: "package-search", id: "package-search",
session: %{ session: %{
"session" => @session, "session_pid" => @session.pid,
"runtime" => @data_view.runtime, "runtime" => @data_view.runtime,
"return_to" => @self_path "return_to" => @self_path
} }

View file

@ -4,7 +4,13 @@ defmodule LivebookWeb.SessionLive.AttachedLive do
alias Livebook.{Session, Runtime} alias Livebook.{Session, Runtime}
@impl true @impl true
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do def mount(
_params,
%{"session_pid" => session_pid, "current_runtime" => current_runtime},
socket
) do
session = Session.get_by_pid(session_pid)
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Attached) do unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Attached) do
raise "runtime module not allowed" raise "runtime module not allowed"
end end

View file

@ -4,7 +4,13 @@ defmodule LivebookWeb.SessionLive.ElixirStandaloneLive do
alias Livebook.{Session, Runtime} alias Livebook.{Session, Runtime}
@impl true @impl true
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do def mount(
_params,
%{"session_pid" => session_pid, "current_runtime" => current_runtime},
socket
) do
session = Session.get_by_pid(session_pid)
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.ElixirStandalone) do unless Livebook.Config.runtime_enabled?(Livebook.Runtime.ElixirStandalone) do
raise "runtime module not allowed" raise "runtime module not allowed"
end end

View file

@ -4,7 +4,13 @@ defmodule LivebookWeb.SessionLive.EmbeddedLive do
alias Livebook.{Session, Runtime} alias Livebook.{Session, Runtime}
@impl true @impl true
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do def mount(
_params,
%{"session_pid" => session_pid, "current_runtime" => current_runtime},
socket
) do
session = Session.get_by_pid(session_pid)
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Embedded) do unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Embedded) do
raise "runtime module not allowed" raise "runtime module not allowed"
end end

View file

@ -4,12 +4,12 @@ defmodule LivebookWeb.SessionLive.PackageSearchLive do
@impl true @impl true
def mount( def mount(
_params, _params,
%{"session" => session, "runtime" => runtime, "return_to" => return_to}, %{"session_pid" => session_pid, "runtime" => runtime, "return_to" => return_to},
socket socket
) do ) do
socket = socket =
assign(socket, assign(socket,
session: session, session: Livebook.Session.get_by_pid(session_pid),
runtime: runtime, runtime: runtime,
return_to: return_to, return_to: return_to,
search: "", search: "",

View file

@ -61,7 +61,7 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do
<div> <div>
<%= live_render(@socket, live_view_for_type(@type), <%= live_render(@socket, live_view_for_type(@type),
id: "runtime-config-#{@type}", id: "runtime-config-#{@type}",
session: %{"session" => @session, "current_runtime" => @runtime} session: %{"session_pid" => @session.pid, "current_runtime" => @runtime}
) %> ) %>
</div> </div>
</div> </div>