Skip to content

Support multiple, isolated LiveSockets on one page - #4435

Open
mat-hek wants to merge 2 commits into
phoenixframework:mainfrom
mat-hek:multi-socket
Open

mat-hek wants to merge 2 commits into
phoenixframework:mainfrom
mat-hek:multi-socket

Conversation

@mat-hek

@mat-hek mat-hek commented Sep 9, 2026

Copy link
Copy Markdown

This is an updated and extended version of #3564. Beyond viewSelector option, it also provides better separation between LiveSockets, so that one LiveSocket's root can be embedded in DOM of a view rendered by another one.

This addresses the main limitation preventing Local LiveView from relying solely on LV's public API.

If this gets merged, I'd like to contribute a public way to destroy LiveSockets, also needed by Local LiveView 😉

@mat-hek

mat-hek commented Sep 16, 2026

Copy link
Copy Markdown
Author

I figured that introducing viewSelector is problematic in many ways. The biggest problem is to make sure that roots belonging to a scoped socket aren't joined by any other socket, and they're there while their socket connects. Another issue is handling navigation and sticky views properly.

Thus, I came up with a different API: LiveSocket.embed(container, url), that makes LV keep more control over when the socket is connected, how the roots are rendered and joined. The main assumptions are that embedded sockets:

  • either leave outside of the main's root or in a phx-ignored container
  • don't trigger/handle navigation
  • can render sticky views, but they're no different than regular views (they're sticky with respect to their socket, and that socket never navigates)

The implementation is partially vibe coded and I'm going to review it in detail, but meanwhile I'm curious what you think.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant