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.

React onChange events not bubbling up on unmount

See original GitHub issue

Do you want to request a feature or report a bug?

I’m reporting a bug.

What is the current behavior?

When attaching an onChange handler to a JSX element, if calling this handler leads to the element being unmounted, then the onChange event never bubbles up in the DOM. This means you can’t listen to it on the document, or basically on anything else than the element itself.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

Example code here: https://codesandbox.io/s/qkr8j85z8j Try it out here: https://qkr8j85z8j.codesandbox.io

Open the console and click around a bit. You will notice that the single checkbox that never changes it’s position triggers both onClick and onChange listeners whereas the other checkboxes that get moved between lists only trigger onClick events.

What is the expected behavior?

I would expect the onChange event to be handled in the same way as the onClick event.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

Tested under these conditions:

  • React 16.3.x and 16.4.x.
  • MacOS 10.13.6
  • Opera 54, Firefox Dev Edition 62, Chrome Canary 70

Behaviour has not changed between versions.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jpkempfcommented, Aug 23, 2018

Thanks for the feedback! It sounds like my best bet at the moment is to await the outcome of #10830.

If I remove the onChange prop from the element and try to use native onChange listeners instead, the element would no longer be a controlled input, which would also be problematic. Our workaround at the moment is to trigger and listen for onClick events instead in cases where onChange would not bubble up. (This happens in an external script outside of React that exists for, sigh, tracking purposes.)

0reactions
stale[bot]commented, Jan 19, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event Bubbling and Event Catching in JavaScript and React
In this article, I'll help you understand event bubbling and event catching like a ... Which Events Do Not Bubble and How Are...
Read more >
Can I make a React Component listen to bubbling change ...
You can use bubbling, of course. Just set onInput or onChange listener on HTML element that your <TargetComponent /> use as a container....
Read more >
How to Use React onClick Events in Class and Functional ...
Finally, React events always bubble, while in JavaScript some events - such as onchange for example - do not bubble up.
Read more >
Testing Recipes - React
When the test ends, we want to “clean up” and unmount the tree from the document . A common way to do it...
Read more >
Bubbling and capturing - The Modern JavaScript Tutorial
No matter where the click happened, it bubbles up to <form> and runs the handler. In form.onclick handler: this (= event.currentTarget ) is...
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