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:
- Temporarily add this line before line 57 in
app/sagas/init.js:
yield call(AsyncStorage.setItem, 'pushNotification', JSON.stringify({ rid: 'GENERAL', name: 'general' }));
- Build and launch the app.
- 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.
In the
restoresaga, the code reads a legacypushNotificationitem from AsyncStorage and then attempts to remove it. However, the innerconst pushNotificationdeclaration shadows the outer variable. SinceAsyncStorage.removeItem()returnsundefined(not the old value),JSON.parse(undefined)throws aSyntaxError. This is caught by thecatchblock which dispatchesappStart({ root: ROOT_OUTSIDE }), forcing the user to the welcome/login screen and silently dropping the notification.Buggy code:
Environment Information:
developbranch)Steps to reproduce:
app/sagas/init.js:Expected behavior:
Actual behavior:
AsyncStorage.removeItem()returnsundefined(it does not return the deleted value).const pushNotificationshadows the outer variable, so it becomesundefined.JSON.parse(undefined)throws aSyntaxError.catchblock on line 62-65 catches the error and dispatchesappStart({ root: ROOT_OUTSIDE }).