Skip to content

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

@Yaddalapalli-Charan-Kumar-Naidu

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions