kminevskiy

kminevskiy

Hey folks,

Does anyone know what could cause the following behavior: I have a live view template and in it I conditionally render a form (based on the value inside the socket assigns).

<%= if length(@users) > 0 do %>
...
<% end %>

When the length changes, it used to render a form, but now nothing happens. If I prepend that first line with, say, a tag <p><%= length(@users) %></p> Everything (showing the form dynamically based on the length of @users list) works as expected. I am pretty sure the code worked as is a few weeks ago before I updated to the latest Live View (but I’m not even sure it’s an issue with Live View), among other packages. Am I missing some new behavior introduced recently or is there something else I’m not doing correctly?

Showing Posts 18 to 9

PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

This might not help in this particular case, but I recently learned that a template gets rendered and send over the websocket connection every time the socket assigns are changed when it isn’t in the .leex format, so when it is a .eex file. Just changing all file formats to .leex reduced the websocket traffic by a lot! So, whenever you do <%= render "my_template.html", assigns %> inside a template, make sure that my_template is of the format .leex :slight_smile:

kminevskiy

kminevskiy OP

Interesting. Do you know / remember if that was the behavior specific to a certain (earlier) release of LiveView? As I mentioned above, I haven’t had any issues with 0.10.0, but after upgrading to 0.11 (and then to 0.12.x) I encountered the aforementioned issue.

carterbryden

carterbryden

I had a similar issue with conditional rendering with liveview. I posted an issue but I just haven’t had enough time to create a reproduction repo publically (client project). In my case it seemed like it might be related to a nested liveview inside a conditional in a liveview template. Still don’t have a fix for it, I just changed the way I was rendering things to work around needing the if statement. I’ll post here if I do figure it out.

kminevskiy

kminevskiy OP

A quick update: it doesn’t look like I can reproduce this bug (?) on a new installation. I suppose it’s specific to my project and I’ll have to debug on my own. I’ll post the solution in this thread.

kminevskiy

kminevskiy OP

Will be happy to. Let me extract that portion and I’ll create an issue. Thank you!

axelson

axelson

Scenic Core Team

Hmm, in that case it seems like it would be worthwhile to provide a reproduction project and post an issue to the project.

kminevskiy

kminevskiy OP

Unfortunately, that didn’t help.

If I add <p><%= Enum.any?(@users) %></p> above the conditional, everything works as expected (first false is being rendered and then, once an event happens, it switches to true and the form inside the conditional is rendered).

So far, I’ve checked the following:

  1. The render function receives pre-computed value (it’s not calculating it on the fly).
  2. IO.inspect/1 actually renders the list correctly.
  3. HTML tags appear to be correct.

Let me know if there’s anything else I could try.

axelson

axelson

Scenic Core Team

It looks like 0.12.1 isn’t actually released on hex yet. But please report back when you try a version with the fix!

kminevskiy

kminevskiy OP

I was looking at that fix a few minutes ago. I’ll update to 0.12.1 and report back.

axelson

axelson

Scenic Core Team

Maybe you could try the master branch. I encountered a fairly similar problem with content disappearing that Chris McCord has fixed on the master branch. I think it is this changelog entry: “Fix component innerHTML being discarded when a sibling DOM element appears above it, in cases where the component lacks a DOM id”

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
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

Other Trending Topics Top

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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews