Today I upgraded LiveView from 0.20.14
to 1.0.9
, and spawning a child LiveView from another LiveView no longer works as before. My parent IndexLive
shows a list of items (table/kanban) and is subscribed to updates via PubSub. It manages filtering, searching, and implements various handle_event
and handle_info
callbacks.
When an item is clicked, I used to spawn its content in a side panel like this:
<%= live_render(@socket, XX.ShowLive,
id: "item-runmode-#{@item_id}",
session: %{...}, sticky: true
) %>
After the Live View upgrade, ShowLive
receives the :not_mounted_at_router
parameter, and trying to work around that (with repeated on mount hooks from the router) leads to this error:
** (RuntimeError) cannot invoke handle_params/3 for XX.ShowLive
because XX.ShowLive was not mounted at the router with the live/3
macro under URL nil
Removing handle_params
to avoid that error then causes issues with push_patch
, because items have steps and we want to change the URL whenever the step changes.
Our router’s configuration for a reference:
live_session :flows_viewable, on_mount: some_hooks do
live "/flows/:org_slug/:flow_slug", XX.IndexLive, :index
live "/flows/:org_slug/:flow_slug/:item_id", XX.ShowLive, :show
end
In general, we had our reasons why not to use live_component
in that particular case like;
- The child live view has its own event-based lifecycle. It can receive both events and Erlang messages independently of its parent, and failures are isolated.
- We also reuse the same module as a full mode live view under a different URL (so it can be mounted in the router).
I believe this change may be the reason
Has anyone encountered this issue or actually found a workaround while keeping a separate child LiveView under LiveView 1.0+?
Any advice would be greatly appreciated!