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?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New
I’m using an Umbrella project for a Phoenix application, and I want to have one Ecto Repo and one PostgreSQL database shared by all apps....
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
Other Trending Topics
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #ai
- #iex
- #graphql
- #elixirconf-us
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
If you updated live view, make sure to
rm -rf node_modules && npm installagain, sometimes it doesn’t pick up changes.kminevskiy
Unfortunately, that didn’t help.
The following code “fixes” the problem (I could make that paragraph tag hidden). But… I wonder why this is happening at all and what exactly changed after the update. Went through the changelog in LiveView (I was running 0.10.0 prior to updating to 0.12.1), but found nothing related to my issue.
NobbZ
You shouldn’t to length like this. This will always iterate and count the full list.
Use something like
match?([_|_], @users)instead.kminevskiy
That’s a great tip, thank you!
benwilson512
Enum.any?(@users)is probably more idiomatic. But none of that should affect whether or not the page updates. @kminevskiy be sure to check the rendered page for HTML validity, if the HTML is invalid this can negatively affect morphdom’s ability to handle updates.Can you provide more code? Maybe
IO.inspect(@users)in the template and see if the output is what you expect?kminevskiy
Thanks for your suggestions.
I remember a few days ago, after I updated the LiveView package, I started the app as usual and was surprised that I couldn’t see the form. Spent some time and through trial and error I found that weird behavior.
IO.inspect(@users)returns a list of maps. Nothing special about it. Plus, I don’t render it in the form - I simply check the length of it and render the form based on the length.dom
You can put an IO.inspect or something in your form template to make sure it’s called. If it isn’t, one thing to check is that your rendering function is pure, it shouldn’t load users from DB for instance, otherwise Phoenix’s change tracking can’t tell that it changed and won’t re-render it. It still worked on 0.10 but 0.11 is better optimized so it actually matters now.
(BTW, there’s an
Enum.empty?function - for lists it checks iflist == []which is as efficient as it gets)kminevskiy
If I put
IO.inspectinside the template, it does properly return a list of users (and it gets updated on events). So the list is populated correctly. I guess I’ll keep digging and trying things.axelson
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”
kminevskiy
I was looking at that fix a few minutes ago. I’ll update to 0.12.1 and report back.