Skip to content

Conversation

@fadi-george
Copy link
Collaborator

@fadi-george fadi-george commented Dec 10, 2025

Description

One Line Summary

Bug:
https://drive.google.com/file/d/1xryp5XAyJEfz7ZogrS5fQPK-mALf5Iyh/view?usp=drive_link

Fix:
https://drive.google.com/file/d/1Uz_lrnhXHSs0S4vgp9FP_9oXBKady-wg/view?usp=drive_link

Details

  • updates event emitter to mimic logic from RNOneSignal java code where I use static instance and call removeHandlers + Observers on the old instance.

Motivation

When doing a reload on the terminal or devtools window, previously any added listeners would just linger so for each reload you would seen an extra log.

Manual testing

Update OSDemo to have:

  useEffect(() => {
    console.log('Initializing OneSignall');
    OneSignal.Debug.setLogLevel(LogLevel.Debug);
    OneSignal.initialize(APP_ID);
  }, []);

  useFocusEffect(
    useCallback(() => {
      const eventMethod = (event: NotificationWillDisplayEvent) => {
        console.log('Event listener called');
        let notification = event.getNotification();
        const data = notification.additionalData as {
          refresh_messages: string;
        };
        console.log('Data:', data);

        if (data?.refresh_messages === 'true') {
          console.log('Preventing default');
          event.preventDefault();
        } else {
          event.getNotification().display();
        }
      };

      OneSignal.Notifications.addEventListener(
        'foregroundWillDisplay',
        eventMethod,
      );

      return () => {
        console.log('Removing event listener');
        OneSignal.Notifications.removeEventListener(
          'foregroundWillDisplay',
          eventMethod,
        );
      };
    }, []),
  );

Run bun run ios in the example project.
Send a test notification to some test subscription.
Click on the react-native terminal.
Should see 1 log per notification.

I also tested w/ additional data (refresh_messages like in issue report). Prevent default should work.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@fadi-george fadi-george requested a review from a team as a code owner December 10, 2025 01:04
@fadi-george fadi-george requested review from abdulraqeeb33, arjun0419, jkasten2 and nan-li and removed request for arjun0419 December 10, 2025 01:24
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