Skip to content

fix: prevent parser crash on app initialization push payload#7049

Open
deepak0x wants to merge 1 commit intoRocketChat:developfrom
deepak0x:fix/init-saga-variable-shadowing
Open

fix: prevent parser crash on app initialization push payload#7049
deepak0x wants to merge 1 commit intoRocketChat:developfrom
deepak0x:fix/init-saga-variable-shadowing

Conversation

@deepak0x
Copy link
Contributor

@deepak0x deepak0x commented Mar 11, 2026

Proposed changes

Fixes a variable shadowing bug in app/sagas/init.js where the inner pushNotification constant reassignment resulted in a SyntaxError: JSON.parse(undefined) crash when AsyncStorage.removeItem returned undefined. This issue resulted in prematurely breaking the restore flow and occasionally looping or forcing a re-login.

Fixed by not reassigning the variable during the remove action and passing the correct outer tracked notification data to the parsing callback.

Issue(s)

Fixes #7014

How to test or reproduce

  1. Verify the app restores from a cold boot correctly.
  2. Confirm the SyntaxError: JSON.parse(undefined) crash no longer appears in logs natively.

Screenshots

N/A

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

N/A

Summary by CodeRabbit

Bug Fixes

  • Fixed a data restoration bug that was preventing stored preferences from being correctly loaded during app initialization.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 90986be6-7314-4333-a200-55f94d0f9c43

📥 Commits

Reviewing files that changed from the base of the PR and between 48c5fc2 and 4f5e32b.

📒 Files selected for processing (1)
  • app/sagas/init.js
📜 Recent review details
🔇 Additional comments (1)
app/sagas/init.js (1)

59-60: Nice fix for the shadowed push payload.

Calling removeItem without reusing pushNotification preserves the original serialized value for JSON.parse, which addresses the JSON.parse(undefined) crash without changing the surrounding restore flow.


Walkthrough

Fixes a variable shadowing bug in the restore saga where AsyncStorage.removeItem() overwrote the outer pushNotification variable with undefined. The fix separates the removeItem operation and preserves the original value retrieved from getItem for subsequent JSON parsing.

Changes

Cohort / File(s) Summary
Variable shadowing fix
app/sagas/init.js
Corrects variable shadowing where the inner pushNotification declaration captured undefined from AsyncStorage.removeItem() instead of preserving the value from AsyncStorage.getItem(). Now removes the item without reassigning the variable, allowing the original value to be JSON parsed successfully.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main bugfix: preventing a parser crash caused by variable shadowing in the init saga when processing push notifications.
Linked Issues check ✅ Passed The PR directly addresses all requirements from issue #7014: fixes variable shadowing, preserves the original pushNotification value, prevents JSON.parse(undefined), and adds test cases covering the fix.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the variable shadowing bug in app/sagas/init.js and adding related test cases; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Fixes JSON.parse(undefined) SyntaxError in app/sagas/init.js when AsyncStorage.removeItem returns undefined.
Closes RocketChat#7014
@deepak0x deepak0x force-pushed the fix/init-saga-variable-shadowing branch from 9a65708 to 4f5e32b Compare March 11, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant