barkerja

barkerja

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

Showing Posts 1 to 7

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.

barkerja

barkerja OP

It is possible to bring the nested LV fields into the main parent LV. These fields are dropdowns that support search with varying datasources, so it made sense to try and isolate those concerns and allow them to manage their own state.

AndyL

AndyL

I ran into problems with nested fields that were difficult to debug. After reducing levels of nesting to two levels everything worked a-ok. Sorry I can’t offer actual guidance - just a data point from a fellow newbie.

barkerja

barkerja OP

@alexgaribay Is this assumption correct? I initially thought it was due to the comprehensions, but I removed those and still saw the same behavior. I assumed due to the fact the changes were contained within the changeset, there was no dirty tracking happening and that’s why we see a full form re-render on any change.

Side note, I enjoyed your ElxirConf talk! Thank you for putting that together.

barkerja

barkerja OP

What sort of issues did you experience?

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.

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:

— All posts loaded —

Where Next? Top

Trending in Questions Top

itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
rlipscombe
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used? I’ve got two Github accoun...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews