fix: clear unprocessedOpenedNotifs queue after replaying to new listener#2632
Merged
fix: clear unprocessedOpenedNotifs queue after replaying to new listener#2632
Conversation
The queue of click events that arrive before any listener is registered was never cleared after being replayed. Each subsequent addClickListener call would refire those old events to all existing subscribers, causing duplicate onClick invocations on already-registered listeners.
18 tasks
abdulraqeeb33
approved these changes
Apr 30, 2026
fadi-george
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
One Line Summary
Clear
unprocessedOpenedNotifsafter replaying so subsequent listener additions don't refire old click events.Details
Motivation
The
unprocessedOpenedNotifsqueue exists to buffer notification click events that arrive before anyINotificationClickListeneris registered (e.g. when the app is opened by tapping a notification and the listener is registered later in the app's startup sequence). When a listener is added, the queue is replayed viaextOpenedCallback.fireOnMain, which fires to all subscribers.The bug: the queue was never cleared after replaying. This caused two problems:
onClickcallbacks for events it already handled.Adding multiple click listeners is officially supported by the SDK (the subscriber list is a
MutableList), and the Flutter wrapper SDK also relies on remove + re-add of listeners during plugin lifecycle, both of which trip the bug.Scope
unprocessedOpenedNotifs.clear()after the replay loop inNotificationLifecycleService.addExternalClickListener.Alternatives considered
EventProducerdoes not currently expose a "fire to single subscriber" method, and adding one would be a broader change. The simplerclear()after replay achieves the same end-state (existing listeners only receive events once, late-added listeners do not receive already-delivered events) with a minimal diff.Testing
Unit testing
Added
queued click events are not refired when a second listener is addedinNotificationLifecycleServiceTests:notificationOpenedwith no subscribers).Verified the test catches the bug by reverting the production change and confirming the test fails.
Manual testing
Reproduced via the OneSignal Flutter SDK example app on Android emulator with multiple back-press → notification-click cycles, confirming that without this fix old click events accumulate and refire on every subsequent listener registration, and that the fix prevents duplicate fires.
Affected code checklist
Checklist
Overview
Testing