Events Don't Get Removed When Re-Using An Element
See original GitHub issueThe Issue
Event listeners (and maybe other attributes, not sure) don’t get removed when re-using an element.
Broken Code <>
const { h, app } = hyperapp
/** @jsx h */
app({
model: true,
actions: {
toggle: model => !model
},
view: (model, actions) =>
<div>
{model && <div onClick={() => alert('🐛')}>a</div>}
<div>b</div>
<button onClick={actions.toggle}>toggle</button>
</div>
})
How to reproduce with the codepen?
- Click
a
. Notice how it properly alerts🐛
- Click
b
. Notice how it doesn’t do anything - Click
toggle
- Click
b
. WTF?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Why do event listeners disappear when reusing a fragment?
Well yeah I know that, that's why I'm reusing the fragment which has an event listener already attached. I'm saying that the event...
Read more >Reuse interactions | Webflow University
Reusing interactions on a series of similar components requires you to replace elements from your original interaction with elements you're trying to ...
Read more >How to Reuse Virtual Event Elements | BeyondLive
Once your online event is over, some elements will no longer be relevant. Updating the website is important to remove elements such as...
Read more >Introduction to events - Learn web development | MDN
This might be a single element, a set of elements, the HTML ... Then the event handler created by the code above can...
Read more >Activation events - Optimize Resource Hub - Google Support
To activate your Optimize experience using an activation event, click Page load [ ... Only newly detected instances of an element are modified...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think is fixed in master.
This is why I don’t like inline events. Event delegation solves this:
With event delegation you can add and delete event targets as you please without worrying about event management.