Skip to content

Stop draining pending events for types with no listeners - #782

Merged
oristanovic merged 1 commit into
mainfrom
fix/event-listener-drain
Oct 22, 2026
Merged

oristanovic merged 1 commit into
mainfrom
fix/event-listener-drain

Conversation

@oristanovic

Copy link
Copy Markdown
Contributor

What do these changes do?

Remove an event type from the listener map once its last listener goes, and
skip any type with no listeners when draining.

Why are these changes necessary?

takePendingEvents consumes the events on the native side, so asking for a
type that has nowhere to deliver them throws them away. removeAllListeners
left an empty array behind, and removeListener left one when the last
listener was removed, so dispatchEvents kept asking for those types and the
events were lost with nothing reporting it.

An app that adds a listener, removes it, and later adds one again loses every
event that arrived in between.

How did you verify these changes?

Compiled this version and the one on main, stubbed react-native, and ran both
against a mock native module:

  • main, after removeAllListeners('push'): takePendingEvents('push') is still
    called, so native hands the events over and they are dropped. Same when the
    last listener is removed individually.
  • this version: not called in either case, and a listener that is still
    registered receives all of its events.

🤖 Generated with Claude Code

takePendingEvents consumes the events natively, so asking for a type with
nothing to deliver them to throws them away. removeAllListeners left an empty
array behind and removeListener left one when the last listener went, so
dispatchEvents kept asking for those types and the events were lost silently.

Both now drop the entry, and dispatchEvents skips an empty one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@oristanovic
oristanovic requested a review from a team as a code owner October 21, 2026 16:15
@oristanovic
oristanovic merged commit 5437c57 into main Oct 22, 2026
1 check passed
@oristanovic
oristanovic deleted the fix/event-listener-drain branch October 22, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants