RocketChat / RocketChat/Rocket.Chat.ReactNative

bug: UserPreferences.getBool() returns null for false values due to || operator instead of ??

Open
#6,983 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

Describe the Bug

UserPreferences.getBool() and UserPreferences.getNumber() in app/lib/methods/userPreferences.ts use the || operator to return null for missing keys. However, this causes stored false (boolean) and 0 (number) values to also be incorrectly returned as null, because false || null → null and 0 || null → null.

// Line 113 — getBool
return this.mmkv.getBoolean(key) || null; // false || null → null ❌

// Line 143 — getNumber
return this.mmkv.getNumber(key) || null; // 0 || null → null ❌

Steps to Reproduce
  1. Set any boolean preference to false (e.g., disable a notification toggle).
  2. Close and reopen the app (or trigger a code path that reads the preference via UserPreferences.getBool()).
  3. Observe that the preference is read back as null instead of false, reverting to its default value.
Expected Behavior

getBool():should return false when the stored value is false, and
getNumber(): should return 0 when the stored value is 0. Only genuinely missing keys should return null.

Actual Behavior

Both false and 0 are coerced to null by the || operator, effectively resetting user preferences to their defaults on every read.

Rocket.Chat Server Version

8.2.0

Rocket.Chat App Version

4.70.0.999999999

Device Name

All devices (platform-independent logic bug)

OS Version

Android 15

Additional Context

No response

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

Open app/lib/methods/userPreferences.ts and inspect getBool at line 113 and getNumber at line 143, starting with how MMKV represents missing values. Confirm that stored false and 0 are preserved while genuinely missing keys still produce null; no test file is mentioned in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
mobile-dev
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.