Skip to content

Conversation

@brainbicycle
Copy link
Contributor

@brainbicycle brainbicycle commented Dec 5, 2025

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:

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:

  1. Start app listeners added to ARNotificationManager module, startListener called listenerCount = 2
  2. Force a dev reload invalidating the bridge
  3. Invalidate called on bridge and the native module causing stopObserving to be called but listenerCount remains 2
  4. Bridge refreshes listeners added again but startObserving never called

Behavior after:

  1. Start app listeners added to ARNotificationManager module, startListener called listenerCount = 2
  2. Force a dev reload invalidating the bridge
  3. Invalidate called on bridge and the native module causing stopObserving to be called but listenerCount reset to 0
  4. Bridge refreshes listeners added again listeners added again, startObserving called after first

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 5, 2025
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Dec 5, 2025
@javache
Copy link
Member

javache commented Dec 8, 2025

Probably not a good idea to have modules that outlive bridge in first place but this seems like unwanted behavior in any case :).

Yes!

No harm in the cleanup though :)

@meta-codesync
Copy link

meta-codesync bot commented Dec 8, 2025

@javache has imported this pull request. If you are a Meta employee, you can view this in D88647586.

@meta-codesync meta-codesync bot closed this in ac8fa25 Dec 11, 2025
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Dec 11, 2025
@meta-codesync
Copy link

meta-codesync bot commented Dec 11, 2025

@javache merged this pull request in ac8fa25.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @brainbicycle in ac8fa25

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants