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
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
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
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
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
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
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #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.