question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extra event incorrectly triggered

See original GitHub issue

Clicking 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:closed
  • Created 5 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
maltiumcommented, Mar 7, 2019

Tested this on Preact 10 alpha0, and it’s still happening.

https://codesandbox.io/s/vj1p70kz4y

2reactions
developitcommented, Feb 3, 2019

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found