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
phx-click function is being called when component renders #1865
Comments
On the repo, just by going to /home you can see on the terminal the JS log |
I was following what is in the documentation on: https://hexdocs.pm/phoenix_live_view/bindings.html#js-commands
|
I just notice, that is actually triggering twice?
|
This is correct. The function is called when you render and it should emit JS commands. The JS commands are then rendered and executed later by the browser on click. So the click will execute the JS commands, not the given function. |
Environment
Elixir version (elixir -v):
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit] [dtrace]
Elixir 1.13.2 (compiled with Erlang/OTP 24)
Phoenix version (mix deps):
{:phoenix, "~> 1.6.2"}
Phoenix LiveView version (mix deps):
{:phoenix_live_view, "~> 0.17.6"}
Operating system:
macOS Monterey 12.1
Browsers you attempted to reproduce this bug on (the more the merrier):
Firefox 96.0.3 (64-bit)
Chrome 97.0.4692.71 (Official Build) (x86_64)
Does the problem persist after removing "assets/node_modules" and trying again? Yes/no:
Yes
Actual behavior
Creating a button on a component like this:
with the function:
When liveview reloads is showing on the terminal:
JS: %Phoenix.LiveView.JS{ops: []}
Which should not happen. Is triggering the phx-click on render. And nothing is happening on click.
I've created a simple repo phoenix application with a component that has the same issue
https://github.com/Narven/weird_phx_click
Expected behavior
I'm expecting that nothing would show in the terminal when the component renders. And that inspect log to only show when I would click the button.
The text was updated successfully, but these errors were encountered: