PhoenixLiveView: mount once, not twice

  1. Is there any way to mount the LiveView once? Every time I navigate to the page with live, mount is called two times. I know that it is called on HTTP request and WebSocket connection, but is there any way to make sure that mount is called only once?

  2. If there is no way to make one mount instead of two, how can I distinguish first mount from the second mount? Do I need to use ugly send(self(), :mounted)?

To make sure that it is not XY, I want to render the page with some data in it, and I want to load this data during initialization of the liveview. I don’t want to load it two times (one for every mount)

If you are using live redirects between pages the web socket connection is reused so you should only get 1 mount.


Yes, that’s true

Thank you!