What will happen to my LiveView component if I go to the next page?

Did you use data-turbolinks-permanent attribute on the element you wanted to persist from page to page?

If you use live_patch between 2 completely different LVs, how does that work when it comes to mount and handle_params? For example, let’s say you want things loaded in both LVs but you only want to fetch them once (without doing any type of caching, since as we all know caching is hard to keep track of).

I thought the difference between patch and redirect was that patch wouldn’t re-run mount. That makes sense if you’re dealing with 1 LV, but with 2, that throws off my whole mental model of how things work.

<%= live_render(@conn, MyChatLive, ...) %> in your root layout would give you an isolated LV that survives live navigation of the main LV from the live route. We replace everything inside the main LV on navigation, so anything outside of it won’t be touched.

10 Likes

Thank you Chris for the comment! :slightly_smiling_face:
In this case, do we need to create the whole app as a LiveView app?

We can discuss a bunch of different scenarios - and we have done so - but unless you effectively go and try things out, it is unlikely we will come up with all the answers that you need.

Now, that mix phx.new --live is available, you can even build something minimal, share the code with everyone, and talk about what worked and what did not. Code speaks more than words in these cases.

8 Likes

Not to derail the conversation (I did use LV + Turbolinks, but not for the same use case), but my problem was with elements that don’t persist between pages. LiveView won’t pick up newly added live views unless you recreate the socket. It’s not a problem if you use LV exclusively, without Turbolinks.

1 Like

I am considering creating a single LiveView as you stated, but am I understanding correctly in that socket assigns are available in the layout? If so, I hadn’t realized that and it would make the single LiveView option much easier to reason.

1 Like

That is correct, if you create your layouts according to this: Phoenix.LiveView — Phoenix LiveView v0.20.2

2 Likes