Skip to content

[Bug]: Android foreground notification display broken on React Native 0.83 (New Architecture) — foregroundWillDisplay handler times out after 30s #1934

@wehrhaus

Description

@wehrhaus

What happened?

Android foreground notifications do not display when using the foregroundWillDisplay listener with React Native 0.83 and the New Architecture enabled. The listener fires, JS executes notification.display(), but the native side never shows the notification. After 30 seconds the native SDK times out with wantsToDisplay=false.

This was working on React Native 0.81 with the exact same JS code and OneSignal configuration. Background notifications work correctly. iOS foreground notifications work correctly. Only Android foreground is affected.

We tested across multiple react-native-onesignal versions (5.2.16 with native SDK 5.1.38, 5.3.6 with 5.7.3, and 5.4.1 with 5.7.6) — all exhibit the same 30-second timeout behavior on RN 0.83.

The root cause appears to be in RNOneSignal.java. The onWillDisplay method unconditionally calls event.preventDefault() and enters a synchronized wait loop on preventDefaultCache. When JS calls notification.display(), the native displayNotification() calls event.getNotification().display() but never removes the entry from preventDefaultCache or calls event.notify() to unblock the waiting thread. On the old architecture this resolved through the bridge's threading model. On the new architecture (TurboModules), the communication deadlocks.

This blocks adoption of Expo SDK 55 / React Native 0.83 for any app using the foreground notification handler on Android.

Steps to reproduce?

1. Create an Expo SDK 55 project with React Native 0.83.4 (New Architecture is mandatory)
2. Install `react-native-onesignal@5.2.16` (or any 5.x version)
3. Register a `foregroundWillDisplay` listener:

OneSignal.Notifications.addEventListener(
  "foregroundWillDisplay",
  (event) => {
    event.preventDefault();
    const notification = event.getNotification();
    notification.display();
  },
);

4. Build and run on Android emulator or device
5. Send a push notification while the app is in the foreground
6. Observe that the notification is never displayed
7. After 30 seconds, logcat shows: `notificationWillShowInForegroundHandler timed out, continuing with wantsToDisplay=false`
8. Send the same notification with the app backgrounded — it displays correctly
9. Test the same code on iOS — it displays correctly

What did you expect to happen?

notification.display() should display the notification as a heads-up notification on Android while the app is in the foreground, the same as it does on iOS and the same as it did on React Native 0.81 (old architecture).

React Native OneSignal SDK version

5.2.16 (also tested 5.3.6 and 5.4.1 — same behavior on all)

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

Fire remoteNotificationReceived
Fire notificationWillShowInForegroundHandler
NotificationWillDisplayEvent.preventDefault(false)
notificationWillShowInForegroundHandler timed out, continuing with wantsToDisplay=false.
kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 30000 ms
    at kotlinx.coroutines.TimeoutKt.TimeoutCancellationException(Timeout.kt:189)
    at kotlinx.coroutines.TimeoutCoroutine.run(Timeout.kt:157)
    at kotlinx.coroutines.EventLoopImplBase$DelayedRunnableTask.run(EventLoop.common.kt:505)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:263)
    at kotlinx.coroutines.DefaultExecutor.run(DefaultExecutor.kt:105)
    at java.lang.Thread.run(Thread.java:1119)
Saving Notification job... isNotificationToDisplay=false

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions