fix: reset listenerCount when invalidating RCTEventEmitter #54809
+1
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
If a subclass of RCTEventEmitter outlives the bridge and the bridge is invalidated, the invalidate method is called on RCTEventEmitter which calls stopObserving but does not change the listenerCount. Once the bridge is recreated and a listener added to the RCTEventEmitter if the listenerCount is > 1 startListening is never called:
react-native/packages/react-native/React/Modules/RCTEventEmitter.m
Line 109 in a9a0268
This just resets the listenerCount to prevent this.
Probably not a good idea to have modules that outlive bridge in first place but this seems like unwanted behavior in any case :).
Changelog:
[iOS] [Fixed] - fix listenerCount not resetting for RCTEventEmitter
Test Plan:
I tested this code via a patch in the artsy/eigen app repo: artsy/eigen#13068
The app was using a native module that posts events over the bridge to handle push notifications.
Behavior before:
Behavior after: