Skip to content

[BUG] Variable shadowing in init saga causes SyntaxError crash and forced logout on app startup #7014

@deepak0x

Description

@deepak0x

In the restore saga, the code reads a legacy pushNotification item from AsyncStorage and then attempts to remove it. However, the inner const pushNotification declaration shadows the outer variable. Since AsyncStorage.removeItem() returns undefined (not the old value), JSON.parse(undefined) throws a SyntaxError. This is caught by the catch block which dispatches appStart({ root: ROOT_OUTSIDE }), forcing the user to the welcome/login screen and silently dropping the notification.

Buggy code:

const pushNotification = yield call(AsyncStorage.getItem, 'pushNotification');
if (pushNotification) {
    const pushNotification = yield call(AsyncStorage.removeItem, 'pushNotification'); // ← shadows outer variable, gets undefined
    yield call(deepLinkingClickCallPush, JSON.parse(pushNotification)); // ← JSON.parse(undefined) → SyntaxError
}

Environment Information:

  • Rocket.Chat Server Version: Any
  • Rocket.Chat App Version: Latest (develop branch)
  • Device Name: Any (iOS / Android)
  • OS Version: Any

Steps to reproduce:

  1. Temporarily add this line before line 57 in app/sagas/init.js:
    yield call(AsyncStorage.setItem, 'pushNotification', JSON.stringify({ rid: 'GENERAL', name: 'general' }));
  2. Build and launch the app.
  3. Observe the crash behavior.

Expected behavior:

  • The app should read the stored push notification, remove it from AsyncStorage, parse it correctly, and deep-link to the relevant room/channel.
  • The user should remain logged in and see the notification content.

Actual behavior:

  • AsyncStorage.removeItem() returns undefined (it does not return the deleted value).
  • The inner const pushNotification shadows the outer variable, so it becomes undefined.
  • JSON.parse(undefined) throws a SyntaxError.
  • The catch block on line 62-65 catches the error and dispatches appStart({ root: ROOT_OUTSIDE }).
  • The user is forcibly kicked to the welcome/login screen.
  • The push notification they tapped on is silently lost.

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