I would like to know what is the recommended way to embed LiveView web applications in a page with a micro-frontend architecture.
I have modified both Phoenix LiveView and Phoenix Live Reload in order to use them in LiveView applications that are encapsulated in a web-component and embedded in a “main container” LiveView application.
The main problem I found is that LiveView references to the global object document, because is meant to be used as a monolithic SPA.
I made changes so that is possible to provide the element that should act as the root document.
Furthermore, I needed the LiveView application to have its own shadow-root node.
You also might want to check LiveState which I developed after first attempting to drop LiveView into a web component. It’s not LiveView, but it designed to be as close I could get DX wise. Used in production for several years at this point, FWIW.
Thank you for the tip. Yes, I think that was the first approach I used but was not aware that one can overcome the sizing problems this way. I’d probably take a look at it.
I think I’ve checked LiveState but would like to keep the development on Elixir mostly. I’ve been working with the frontend-backend approach and working only in the backend has became a more appealing approach. But will consider the pros and cons and check if LiveState can be a better solution to my problem.
I’m doing the liveviews-in-iframes approach while migrating my frontend from a 100% Vue SPA to mostly Liveview. New views are Liveview only, and Vue is still rendering the outer page. Indeed this sizing problem can be overcome, and of course parent-child communication adds a bit of plumbing, but it stays quite straightforward.
I have not run into issues related to this embedding of Liveview in iframes in an SPA in production.
I will give it a try. I had a bit of bad memories when I did this for many years ago so that’s why ive tried to avoid it but hopefully is less hassle nowadays.