RocketChat / RocketChat/Rocket.Chat.ReactNative
[BUG] Variable shadowing in init saga causes SyntaxError crash and forced logout on app startup
Nobody has claimed this yet.
- 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 (
developbranch) - 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()returnsundefined(it does not return the deleted value).- The inner
const pushNotificationshadows the outer variable, so it becomesundefined. JSON.parse(undefined)throws aSyntaxError.- The
catchblock on line 62-65 catches the error and dispatchesappStart({ root: ROOT_OUTSIDE }). - The user is forcibly kicked to the welcome/login screen.
- The push notification they tapped on is silently lost.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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