victor23k

victor23k

Hi all! I come with a proposal to create LiveViews inside the shadow DOM. At Doofinder, we have experience building embeddable LiveView apps, and we think it is a valuable addition to the ecosystem, as it allows for fast interaction widgets.

Why

The main problem with multiple LiveViews from different origins coexisting in the same DOM is duplication of events and elements. If we leverage the shadow DOM, we could bypass these limitations while also allowing for easier communication between the host page and the LiveView widgets.

Why use shadowDOM and not <iframe>

While there has already been discussion about doing this with <iframe>, We think the Shadow DOM is more adecuate for the following reasons:

  • SEO. If the LiveView widget is loaded with the page, the content would count to the host page, not the origin of the LiveView as it would happen with <iframe>.
  • Performance. No need to load a full DOM.
  • Session cookie: Safari conflicts with <iframe> and cookies. ref
  • Better comunication with host page and with other apps. No need for postMessage().

It is worth noting that I haven’t mentioned anything about WebComponents, because the goal of this is not adding support for them. The approach we present would only mean encapsulating the DOM where the LiveView lives. Here there was a related discussion, and I think some of the problems exposed there could be solved.

What would change

This feature would be a new way to use LiveView and it would not affect regular LiveViews

Doing a quick prototype I identified some areas of work:

  1. Add a way to configure a LiveView to create a shadow DOM.
  2. Places where document is used to find a DOM element should support using the shadowRoot.
  3. Event listeners need to be added to the shadowRoot instead of window.

We volunteer to work on this and implement it.


So what are your thoughts on this? Would you benefit from this feature? Are the core maintainers open to us working on this?

Showing Posts 1 to 8

rhcarvalho

rhcarvalho

Interesting idea! It does mean the “host page” must be a Phoenix LiveView app, right? Unlike an iframe, I’m understanding you’re not interested in embedding LiveViews into third-party pages but pages under your control, is that right?

:light_bulb:Reminds me of the idea of “islands” in the JS ecosystem.

victor23k

victor23k OP

The goal is to make it work under any type of host page, also regardless of who owns the host page!

rhcarvalho

rhcarvalho

Searching for something unrelated on the forum I accidentally found Running LiveView inside a web component with shadow DOM and thought it could be a reference point for this conversation.

steffend

steffend

Phoenix Core Team

Hey @victor23k,

I’d be happy to review a PR that explores this!

victor23k

victor23k OP

Thanks! I’ll work on that. We had planned to open source a library with the functionality described that we use internally. The goal was to see if more people are interested in it. It can serve as a preview until the PR hopefully gets merged to LiveView.

westmark

westmark

@victor23k I’m really looking forward to trying out your library. Any update on this front?

Werner

Werner

Hi, have you seen this LiveViewPortal from Doofinder?

victor23k

victor23k OP

I forgot to add the link here, but @Werner got me covered :wink:. Check it out and ask any questions in the library thread!

— All posts loaded —

Where Next? Top

Trending in Proposals: Ideas Top

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews