New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LiveView AlpineJS @click doesn't work after a new item is inserted #1203
Comments
Could you try loading Alpine.js with webpack instead of CDN? I mean editing
then running My hypothesis is that when you create |
You need to import it in app.js as well if you want to have it bundled with webpack |
Did you try to replicate this without liveview? It might be a problem with Alpine.js itself, as I stumbled upon a bug that is still not solved: alpinejs/alpine#756 (demonstrated here: https://jsbin.com/zucomuguza/1/edit?html,js,console,output) |
Thanks all for the advice. @tcoopman Yes, trying with webpack and an error shows up that may be as a result of how Alpine processes code in an eval-like way; my understanding is that Alpine will be improving in this area soonish: alpinejs/alpine#855 @dvic I didn't try without LiveView, because I need LiveView. I replaced Alpine with vanilla JS, which is working fine with LiveView, so I aim to revisit this once the above Alpine improvement happens. If an admin wants to close this for now, that's fine. Thanks all! |
Provided you have |
I've tried the advice in the similar issue: #996
Environment
Elixir version (elixir -v): 1.11.1
Phoenix version (mix deps): 1.5.6
Phoenix LiveView version (mix deps): 0.14.7
NodeJS version (node -v): v14.15.0
NPM version (npm -v): 6.14.8
Operating system (uname -a): Darwin … 19.6.0 Darwin Kernel Version 19.6.0 …
Browsers you attempted to reproduce this bug on (the more the merrier): Firefox current, Chromium current
Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: yes
Actual behavior
Given: LiveView renders a page of user blog posts, and each post has an Alpline @click toggle to show/hide more info.
When: user clicks the toggle button.
Then: nothing happens on any post that was inserted after the page loaded. (For comparison, everything works fine on posts that were loaded during the page load. For diagnosing, everything work fine when I reload the page i.e. the posts that didn't work do start working as expected.
Expected behavior
The click works. (Same as it does on the posts that were loaded during the page load).
Details
I'm loading Alpine in
root.html.leex
as typical:The
app.js
file includes the recommended code from Chris McCord:The text was updated successfully, but these errors were encountered: