Skip to content

fix: stabilize observer lifecycle and asynchronous state snapshots - #1974

Merged
fadi-george merged 3 commits into
OneSignal:mainfrom
OskarEichler:codex/onesignal-observer-lifecycle
Sep 1, 2026
Merged

fix: stabilize observer lifecycle and asynchronous state snapshots#1974
fadi-george merged 3 commits into
OneSignal:mainfrom
OskarEichler:codex/onesignal-observer-lifecycle

Conversation

@OskarEichler

Copy link
Copy Markdown
Contributor

Description

One Line Summary

Clean up listeners across module reloads, make native subscriptions and internal observers idempotent, dispatch a stable listener snapshot, and keep newer permission/subscription events from being overwritten by startup reads. Handle rejected startup reads without unhandled promise rejections. Restore default foreground display when the final JS foreground listener has been removed.

Compatibility and observable changes

No public signature or native SDK version changes. Listener mutations apply to the next event dispatch; a self-removing handler no longer skips the following handler. Notifications without a remaining foreground listener display normally. Active handlers retain suppression and deferred-display control. Startup getter failures now produce one warning instead of an unhandled rejection.

Details

Motivation

The source audit reproduced the failure paths described below. This PR contains only the associated fix; unrelated audit changes are in separate PRs.

Scope

  • src/index.ts
  • src/events/EventManager.ts

Testing

10 independently applied external JS diagnostics, including eight reproduced baseline failures and active-suppression controls. Existing 262 tests and unchanged coverage thresholds pass. This does not implement the native waiting/timeout API proposed in #1859.

Each code/tooling fix was also applied independently to upstream commit a70312207cf094ac361eaa9196c317acb175c2cd and passed its targeted external actual-source diagnostics. Documentation snippets were checked separately. Native diagnostic harnesses use bridge/SDK doubles and are not an end-to-end push test.

On the combined audit branch:

  • Existing SDK suite: 5 files, 262 tests pass; unchanged 95% coverage thresholds pass.
  • vp check: formatting, lint and type checks pass; native Spotless check passes.
  • Both example apps: Android Debug and unsigned iOS Simulator builds pass.
  • Both example apps: iOS and Android production Metro bundles pass.

No checked-in test files were added or modified; regression evidence comes from external diagnostic harnesses and the existing suite. No physical-device, live notification delivery, Appium/BrowserStack, or release-workflow execution is claimed. The no-location example's stale native lock was updated locally to resolve the current SDK for verification; generated locks are not part of this PR.

Checklist

  • Required description sections completed.
  • Scope and observable/API behavior explained.
  • Diff reviewed and targeted regression checks run.
  • Automated checks and device-testing limitations documented.

@OskarEichler
OskarEichler requested a review from a team as a code owner August 27, 2026 23:46
OskarEichler and others added 2 commits September 1, 2026 15:35
Replacing the manager stored on the global tears down the native
subscriptions of whichever module instance created it, so listeners
registered through that instance stop receiving events for the lifetime
of the process. Reuse that manager instead, which also keeps a duplicate
install from double-subscribing to the native emitters.

Drops the default-display fallback from dispatchHandlers: foreground
events no longer route through it, and the native callback already
displays by default in its finally block.

Adds regression tests for the manager lookup, the startup read races,
listener mutation during dispatch, setupListeners idempotence, and
clearListeners.

Co-authored-by: Cursor <cursoragent@cursor.com>
@fadi-george
fadi-george force-pushed the codex/onesignal-observer-lifecycle branch from 41852cf to b71ced8 Compare September 1, 2026 22:43
@fadi-george

Copy link
Copy Markdown
Collaborator

Rebased onto main and pushed a follow-up commit with a few changes to the logic here.

The global manager lookup now reuses the existing manager instead of replacing it. Replacing it tore down the native subscriptions of whichever module instance created it, so with a duplicate install the app's listeners stayed attached to a manager that no longer received events. I reproduced this on an iOS simulator with two copies of the package in one bundle: on this branch the app stopped receiving events entirely, and after the change both copies share one manager and events flow through both.

Also removed the default display fallback in dispatchHandlers. Foreground events no longer route through that path after #1989, which already displays by default in the native callback's finally block, so the branch was unreachable and duplicated that behavior.

Added tests for the manager lookup, both startup read races, the failed startup read warning, listener removal during dispatch, setupListeners idempotence and clearListeners. 279 tests pass and coverage stays above the thresholds.

Heads up that the description is now out of date, since it still mentions the clearListeners cleanup and the display fallback.

Co-authored-by: Cursor <cursoragent@cursor.com>
@fadi-george
fadi-george merged commit 1745e6c into OneSignal:main Sep 1, 2026
2 checks passed
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.

2 participants