-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[Android] [BackAndroid] New listeners registered while back event is handled also receive the current event #5781
Comments
Hey feichngr, thanks for reporting this issue! React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
|
Summary: …while an event is dispatched While it is guarded, a copy of the Set is created before listeners are added or removed. The event dispatch loop continues with the old Set of listeners. This PR modifies `BackAndroid` to match the proposal at the end of #5781. Closes #5783 Reviewed By: svcscm Differential Revision: D2911282 Pulled By: foghina fb-gh-sync-id: 34964ec3414af85eb9574bbcef081238fc67ffaf
Summary: …while an event is dispatched While it is guarded, a copy of the Set is created before listeners are added or removed. The event dispatch loop continues with the old Set of listeners. This PR modifies `BackAndroid` to match the proposal at the end of facebook#5781. Closes facebook#5783 Reviewed By: svcscm Differential Revision: D2911282 Pulled By: foghina fb-gh-sync-id: 34964ec3414af85eb9574bbcef081238fc67ffaf
Hi there! This issue is being closed because it has been inactive for a while. But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/android-backandroid-new-listeners-registered-while-back-event-is-handled-also-receive-the-current-event ProductPains helps the community prioritize the most important issues thanks to its voting feature. Also, if this issue is a bug, please consider sending a pull request with a fix. |
I just faced for me unexpected behavior when (indirectly) registering a listener to
BackAndroid
while an event is currently handled.In my project I use a
Root
component type, which calls a function provided to it via theonBackPress
prop. It looks something like this:Now if the back button is pressed and, as part of the
onBackPress
function, the currentRoot
element is replaced by a new one, the newRoot
element'scomponentDidMount
is executed beforeonBackPress
returns, adding the new event listener toBackAndroid
.Problem is:
BackAndroid
will add the new listener to theSet
of listeners it loops over and eventually call the newly added listener for the same event it was created by.I think the better behavior would be not to modify the
Set
of listeners while looping over them to dispatch an event. In case theSet
needs to be modified create a copy, apply the modification there and continue to use the originalSet
to complete handling of the current event.The text was updated successfully, but these errors were encountered: