RocketChat / RocketChat/Rocket.Chat.ReactNative

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

Open
#7,014 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 bug type: bug
Dominant language
TypeScript
Stars
2.4k
Forks
1.5k
Avg merge
1d 18h
Merged PRs (30d)
90

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in app/sagas/init.js, focusing on the restore saga and the pushNotification handling around lines 57 and 62-65. Reproduce with the documented AsyncStorage.setItem setup, then verify that startup parses the stored notification, removes it, deep-links correctly, and does not dispatch the welcome/login root.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.