-
Notifications
You must be signed in to change notification settings - Fork 987
add auto_connect option to LiveView mount options #3704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
107cb2f
to
3464573
Compare
lib/phoenix_live_view.ex
Outdated
This is useful when you have a static page that does not require | ||
any connected functionality, but should render over the existing | ||
connection when navigating from an already connected LiveView. | ||
Defaults to `true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what happens if auto_connect is false and I go to a page also with auto_connect=false, trying to use patch or navigate? I assume it does a full page navigation anyway? We should document this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Each link will perform a full page reload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits in the docs but, assuming it doesn't connect between auto_connect=false, it LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid this adds one more variant to a LiveView which makes it harder to reason about a LiveView's lifecycle.
In my mind a "live view" is meant to be connected.
to not automatically connect to the server on dead render. | ||
This is useful when you have a static page that does not require | ||
any connected functionality, but should render over the existing | ||
connection when navigating from an already connected LiveView. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A LiveView with auto_connect: false
is special in that its reactivity would depend whether you arrived over a regular HTTP request or live navigation.
What would happen if the socket disconnects for some reason (e.g. user drives through a tunnel or server is redeployed)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the LiveView is connected once and disconnects, it will reconnect as usual. This only affects the very first page load.
2ca45d7
to
9d684d4
Compare
1552fa0
to
e1e94dd
Compare
to specify that a LiveView should not automatically connect on dead render. When navigated to and there's already a connection established, this option has no effect. See https://elixirforum.com/t/liveview-feature-to-cancel-second-render/67770
Co-authored-by: José Valim <[email protected]>
e1e94dd
to
a8756c0
Compare
Add auto_connect option to LiveView mount options to specify that a LiveView should not automatically connect on dead render. When navigated to and there's already a connection established, this option has no effect.
See https://elixirforum.com/t/liveview-feature-to-cancel-second-render/67770