Extra event incorrectly triggered
See original GitHub issueClicking on Button 1 causes both onButton1Click() and onButton2Click() to be triggered. Only onButton1Click() should be called if Button 1 is clicked. Interestingly, setting the key on the div containing Button 2 prevents this issue from happening.
Same code works as expected with React and testing indicates that the issue was introduced in Preact 5.x.
Here’s a demo of the issue on jsfiddle.
import { Component, render } from "preact";
class App extends Component {
constructor(props) {
super();
this.state = {
showSection: true
};
}
render() {
const section = (
<div>
<div />
<div>
<div onClick={this.onButton1Click}>Button 1</div>
</div>
</div>
);
return (
<div>
{this.state.showSection && section}
<div>
<div>
<div />
</div>
<div onClick={this.onButton2Click}>Button 2</div>
</div>
</div>
);
}
onButton1Click = () => {
console.log("button 1 click");
this.setState({ showSection: false });
};
onButton2Click = () => {
console.log("button 2 click");
};
}
render(<App />, document.getElementById("root"));
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Extra event incorrectly triggered · Issue #1290 · preactjs/preact ...
This is caused by microtasks being flushed between event propagation. My understanding of the flow: click event is dispatched at target Button 1;...
Read more >Java Swing issue, why is a changeEvent firing extra events ...
While trying to learn JButton events I'm getting confused because of a problem. The sample code I'm using is here. The code is...
Read more >How to troubleshoot Meta Pixel error and warning messages ...
Click See affected URLs to see which pages of your website may contain duplicate or incorrect event code. Remove extra event code snippets...
Read more >How to handle typical event-driven architecture failures
This article reviews some of the common event-based architecture failures development teams face and explores some ways to address them.
Read more >Event listeners not working? 3 key areas to troubleshoot
Are your event listeners not working as you'd expect? Here are 3 key areas to troubleshoot to help you get everything triggering as...
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 FreeTop 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
Top GitHub Comments
Tested this on Preact 10 alpha0, and it’s still happening.
https://codesandbox.io/s/vj1p70kz4y
I haven’t fully finished looking into this, but if it’s recycling-related, there’s no recycling whatsoever in the upcoming major update. Let’s hope this goes away then!