nikhgupta

nikhgupta

Hello,

I am really really new to Elixir, and although I have tried to get started with it earlier - I, finally, started rewriting a monolith Rails app using Phoenix to fix a few things we were having troubles with (and o’course, learning new stuff helps).

So far, I am loving the components we have ported to our Elixir application, and Phoenix LiveView has been incredibly useful to speed things up. We were using Vue.js earlier, but the development workflow is so easy with LV, once we got a hang of it.

However, there is one thing we could not find any reference to. We have a huge root layout, and like in the previous Rails application we have it split across several partials. We are using LiveView on top of it, and it works beautifully. Although, the diffs are pretty huge. I figured that LiveView is sending those partials in the diff, probably because it only searches for diffs at the first level, and considers nested partials as updates to simplify diff calculation.

So, e.g. the layout is:

<%= @count %>
<%= render "partials/_nested.html", assigns %>

In the above case, LiveView diffs are returning the whole content of partials/_nested.html. If we remove the partial, and include the HTML in the code directly - the diffs go back to sane size. I guess the same warning applies here - avoid content_tag in your templates.

But, to keep the code DRY - it would be really great, if we can simply ignore such “static” partials from the diff calculation somehow? I am not sure how the diff calculation works (haven’t gone through that part of code). If possible, we would like to mark partials that do not change once rendered, and have them be ignored by LiveView in diffs. Any suggestions regarding this?

Showing Posts 1 to 8

idi527

idi527

:waving_hand:

Have you considered turning the partials into live components?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Is your partial a .eex or .leex file?

Dlacreme

Dlacreme

I know this is quite old but I believe this is what most of us are looking for: Phoenix.LiveComponent — Phoenix LiveView v1.2.5

david

david

For folks in the future, I thought I’d also point out that there are both Phoenix.Component and Phoenix.LiveComponent (as @Dlacreme identified). There are some “partial” use cases that might be satisfied by the former. As I’ve seen Component and LiveComponent used interchangeably in some tutorials, thought it worth mentioning.

maxie

maxie

Don’t use LiveComponents if it’s not really necessary. Use function components instead. IMHO, live component is a new process, so if you have for instance 4 liveview components you have 4 processes, it’s not elixirish!!! and also you could have a headache later passing the properties from one to other.
Also there’s no need to use function component if you don’t use them in at least one other part of the code. So it’s better to use templates like parts of the code in order not to have a spaghetti code.

The question is it possible in Elixir to render just a part of code like template
Example:

... ...
...
<%= render some template of terms_and_conditions.html.heex %>
....

…

this terms_and_conditions file could have some static variables (constants) for example. But in order not to have spaghetti we decouple it to a separate file

D4no0

D4no0

Not true, all live components are part of the same process.

sodapopcan

sodapopcan

To add volume to @D4no0 's comment, LiveComponents are NOT new processes and it’s important to understand that. I do agree, however, to not use a live component if you can get away with a function component. I always reach for function components first then refactor into live components once it starts to make sense to encapsulate some slice of state and behaviour within a LiveView, especially if it can be re-used elsewhere.

maxie

maxie

Ok, yes, the same process, agreed. My fault. I meant other thing: "They run inside the LiveView process but have their own state and life-cycle. For this reason, they are also often called “stateful components”. Do we always need state?! I say it because there are a lot of tutorials where every time for creating a template or a simple view a live_component is created.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews