-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Duplicate event handlers being added to elements with ids during LiveView update. #1171
Comments
The difference in behaviour occurs because morphdom uses the node's id to identify nodes that should be moved rather than deleted and reinserted. I think the bug occurs because element moves aren't distinguished from element creations. With this in mind, I can write an version that triggers the issue without liveview:
I expect that clicking a button will increment the counter and move that button to the end. When the buttons get moved duplicate event handlers get attached and the counter starts to go up in steps of more than one. |
I think I'm seeing something very similar. Going to see if the PR solves my issue when it goes through. |
Hi guys. So this issue still exists when your event is attached to a node within the node you are moving. I have updated the example to demonstrate this : <div id="to-input-div" x-data="{'x': 0}">
<span x-text="x">0</span>
<div id="a"><button x-on:click="x += 1; $el.appendChild(document.getElementById('a'))">A</button></div>
<div id="b"><button x-on:click="x += 1; $el.appendChild(document.getElementById('b'))">B</button></div>
<div id="c"><button x-on:click="x += 1; $el.appendChild(document.getElementById('c'))">C</button></div>
</div> |
Are you interested in digging into the issue? Even if you submit a PR that only updates the relevant test to fail, it'll probably make it easier for someone else to solve Couple of other notes:
|
@HugoDF - I can confirm that the previous fix has not yet been released. As requested I have opened up a PR with a failing test here - #1265 It would appear that the previous solution tracks in the |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I've been running into a weird bug with event handlers being added more than once to elements when using AlpineJS with LiveView.
This is a fairly minimal demonstration:
When you enter a message and hit enter it gets added once, and a second copy of the event handler is added. The second message is added twice, the third four times, the fourth eight.... Clicking the button with an id does the same thing, but clicking the button without id only adds it once. (Checking registered event handlers confirms that an event handler has been added for every message added to the list.)
This is the
phx-hook
:And I have the callback calling
Alpine.clone
fromonBeforeElUpdated
.(Running alpinejs 2.8.1 and phoenix_live_view 0.15.4).
The text was updated successfully, but these errors were encountered: