barkerja

barkerja

LiveView Form With Nested LiveView Fields

We are currently experiencing an issue with a form we recently created that has several nested LiveView fields. Our form is currently defined as such:

<%= f = form_for @changeset, "#", [class: "liveview-container", phx_change: :validate, phx_submit: :save] %>

The primary issue we are experiencing is our nested LiveView fields are remounted on the parent’s state change; it does not matter what changed on the socket’s assigns, it will cause a full re-render of the form.

This is particularly problematic for our nested LiveView fields because we load data on mount, which the form’s on change exacerbates. In addition to this, we are also seeing all of the static and dynamic bits being sent on every change. I assume this might be an issue with how diffs are handled with something like the changeset?

A link to the parent template (ignore .eex extension, had to use it instead of .leex for GitHub to highlight): live_view_form.html.eex · GitHub

Most Liked

alexgaribay

alexgaribay

Phoenix Core Team

With the way it was structured, any change to the underlying changeset will cause a new nested LiveView to spawn for your fields. Every time that happens, the full rendered struct with the statics and dynamics will be sent to the client.

I’m glad you enjoyed it! :+1:

alexgaribay

alexgaribay

Phoenix Core Team

This is by design for nested LiveViews. Since the session being passed is technically changing, you get a new LiveView process on each change.

Is there a way you can do this without a nested LiveView? I’d recommend adding any event handlers in the parent and having a function that renders each field.

AndyL

AndyL

I have a clock component that updates every second. When I embed it three levels deep, it fails intermittently, like once every ten page refreshes. Couldn’t figure out why. Then I wrote the clock logic into the second-level component, and it runs perfectly. Also experienced problems when I had live-views embedded in the page layout (header and footer), with a live view rendering in the body. The initial render would go fine, but when I used push-state and the back button, the body live-view was rendered in the header. Probably newbie error, and maybe subtle bugs in the new tech. Even with these teething problems I’ve written probably the best live-UI of my life. More to come. I hope that eventually we can create libraries of live-components that can be deeply nested.

Where Next?

Popular in Questions 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
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48475 226
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54250 245
New

We're in Beta

About us Mission Statement