hiramegl

hiramegl

Canonical way to use LiveView in a micro-frontend architecture

Hi,

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.

An schematical image would look like this:

The PoC is found here: GitHub - hiramegl/suite · GitHub
The database references are not needed and could be removed.

I’ve probably overcomplicated things but have not found a better approach.

Another constraint is that I do not want to use React or Vue to build the frontend and just use Phoenix/Elixir for the backend. I Found this related thread LiveView independent micro-frontend idea: somewhat stuck + repo - #8 by garrison but it is not what I’d like to use.
I’d like to use only LiveView.

Also saw the PR for a patch that solves more or less the problem that I have, but it seems to have conflicts and is not solved yet.

https://github.com/phoenixframework/phoenix_live_view/pull/3564

Thank your for your help beforehand!

Best regards,

/Hiram

Most Liked

superchris

superchris

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.

derek-zhou

derek-zhou

The only way to embed liveview that works out of the box is to use an iframe. Then you will have the obvious sizing problem, which can be overcame if:

  • You control everything and everything is served from the same domain
  • Your iframe embedding scheme is static and not too complicated

This blog post discussed a simple way to coordinate sizing between parent and child

dblack

dblack

You might want to check out this: LiveViewPortal - embed LiveViews in other websites

Where Next?

Popular in Questions Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement