Greetings comrades,
I have discovered that “sticky” LiveViews get remounted (breaks stickiness, resets state) when live navigating to a route that lives in a different live_session
in the router.
I made a repo here to demonstrate the problem:
Sticky LiveView practice
I do not know if this is expected behavior or a bug.
If it is expected then I will open a PR to add this vital information to the docs (Phoenix.Component — Phoenix LiveView v1.0.0-rc.6 ).
If it is a bug then I will open an issue in the live_view github repo, maybe even have a go at fixing it myself (hold my beer).
I see at least one other person is already aware of this limitation:
Hi,
I have a problem where i have a stream that resets in a child liveview.
The liveview is sticky and i’m redirecting to a different liveview in the same live_session. So the liveview is not remounted.
I have defined the stream like this:
<div
id={"auction-#{@active_auction_id}-messages"}
phx-update="stream"
data-page={@query_params["page"]}
class="min-w-[28rem] flex h-full grow flex-col gap-2 overflow-auto overflow-x-clip scroll-auto bg-white px-6 py-3 pb-2"
>
…
Maybe this is in the docs and I just missed it?
UPDATE: Yup, I’m blind:
https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.Router.html#live_session/3
Redirecting between live_session
s will always force a full page reload and establish a brand new LiveView connection.