Skip to content

[Bug]: TypeError: Cannot read properties of undefined (reading 'forceDeltaQueueProcessingOnAllExecutors') #178

@damianobarbati

Description

@damianobarbati

What happened?

I don't understand how to properly initialize and/or login the user. I get an error when I login which is not catchable.

NotificationBell.tsx:53 OneSignal.login
LoginManager.ts:138 TypeError: Cannot read properties of undefined (reading 'forceDeltaQueueProcessingOnAllExecutors')
    at ee._login (LoginManager.ts:42:30)
    at async ee.login (LoginManager.ts:24:5)
    at async D.login (OneSignal.ts:109:11)
overrideMethod @ hook.js:608
_login @ LoginManager.ts:138
await in _login
login @ LoginManager.ts:24
login @ OneSignal.ts:109
(anonymous) @ react-onesignal.js?v=d04993a6:50
processItem @ ProcessOneSignalPushCalls.ts:9
push @ OneSignal.ts:266
processOneSignalDeferredArray @ ReplayCallsOnOneSignal.ts:12
xs @ pageSdkInit.ts:38
(anonymous) @ pageSdkInit.ts:50
(anonymous) @ pageSdkInit.ts:50

My component:

export const NotificationBell = ({ className, userId }: Props) => {
  const [consentStatus, setConsentStatus] = React.useState<null | 'default' | 'granted' | 'denied'>(null);
  const navigate = useNavigate();
  const { t, i18n } = useTranslation();

  const { data: rowsCount } = useSWR(['/notification/count', { read_at: null }], POST);

  // when we unmount the component, we need to log out the user from OneSignal and reset the consent status to unknown
  React.useEffect(() => {
    return () => {
      setConsentStatus(Notification.permission);
      console.log('OneSignal.logout');
      void OneSignal.logout();
    };
  }, []);

  // when we mount the component or user/language changes, we need to run all the logic
  React.useEffect(() => {
    (async () => {
      if (!OneSignal.User) {
        await OneSignal.init({
          appId: import.meta.env.VITE_ONESIGNAL_APP_ID,
          allowLocalhostAsSecureOrigin: true,
          welcomeNotification: { title: t('Welcome on ATLAS!'), message: t('You will now receive notifications relevant to you.'), url: window.location.href },
        });
      }

      if (!OneSignal.User.externalId) {
        try {
          console.log('OneSignal.login');
          await OneSignal.login(userId);
        } catch (error) {
          console.warn('OneSignal bug?');
          console.error(error);
        }
      }
      i18n.on('languageChanged', (lng) => OneSignal.User.setLanguage(lng));

      // we check if the user is subscribed to notifications, but we can't rely on OneSignal.User.PushSubscription.optedIn since it doesn't let us know if the user was prompted
      setConsentStatus(Notification.permission);
    })();
  }, [userId, t, i18n]);

What browsers are you seeing the problem on?

Chrome (Chromium)

What operating system are you running?

MacOS

Steps to reproduce?

The useEffect I provided

What did you expect to happen?

No errors

Relevant log output

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions