phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6.21k stars 930 forks source link

use push_navigate in nested liveview causes full reload #3424

Closed limeuser closed 3 weeks ago

limeuser commented 1 month ago

Environment

Actual behavior

In my application, i use nested liveview in layout to implement sidebar. In sidevar liveview, using <.link navigate> navgite to liveview is ok, but using push_navigate in click handle_event cause full reload, and liveview socket is reconnected.

app.html.heex implement sidebar as nested liveview in layout

<div>
  <%= live_render(@socket, TestliveWeb.SideBarLive, sticky: true, id: :side_bar) %>
  <%= @inner_content %>
</div>

side_bar_live.ex

article_live.ex

defmodule TestliveWeb.ArticleLive do
  use TestliveWeb, :live_view

  @impl true
  def render(assigns) do
    ~H"""
    <div>
      <%= @id %>
    </div>
    """
  end

  @impl true
  def mount(%{"id" => id}, _session, socket) do
    {:ok, assign(socket, id: id)}
  end
end

main_live.ex

defmodule TestliveWeb.MainLive do
  use TestliveWeb, :live_view

  @impl true
  def render(assigns) do
    ~H"""
    <div>
      <.link navigate={~p"/articles/1/show"}>article1</.link>
    </div>
    """
  end
end

router

 scope "/", TestliveWeb do
    pipe_through :browser
    live "/main", MainLive, :index
    live "/articles/:id/show", ArticleLive
  end

Expected behavior

SteffenDE commented 1 month ago

This is fixed in https://github.com/phoenixframework/phoenix_live_view/pull/3280.

cc @chrismccord

chrismccord commented 3 weeks ago

Closed via #3470