Skip to content

fix: prevent falsy values from being coerced to null#6984

Open
Yaddalapalli-Charan-Kumar-Naidu wants to merge 1 commit intoRocketChat:developfrom
Yaddalapalli-Charan-Kumar-Naidu:fix/user-preferences-falsy-values
Open

fix: prevent falsy values from being coerced to null#6984
Yaddalapalli-Charan-Kumar-Naidu wants to merge 1 commit intoRocketChat:developfrom
Yaddalapalli-Charan-Kumar-Naidu:fix/user-preferences-falsy-values

Conversation

@Yaddalapalli-Charan-Kumar-Naidu
Copy link
Contributor

@Yaddalapalli-Charan-Kumar-Naidu Yaddalapalli-Charan-Kumar-Naidu commented Feb 13, 2026

Proposed changes

The getString(), getBool(), and getNumber() methods in UserPreferences currently use the || operator to return null when a key is missing.

This unintentionally coerces valid falsy values into null:

  • false || null → null
  • 0 || null → null
  • "" || null → null

As a result, legitimate stored preferences (e.g., disabled toggles, zero counters, or empty strings) are read back as null instead of their actual values.

This PR replaces the || null pattern with an explicit undefined check, ensuring:

  • Only truly missing keys return null
  • Valid falsy values (false, 0, "") are preserved correctly

The change is minimal, safe, and non-breaking.

Issue(s)

Closes #6983

How to test or reproduce

  1. Navigate to Settings → Security & Privacy → Screen Lock
  2. Enable Screen Lock and set a passcode
  3. Toggle Biometry OFF
  4. Add a console.log inside getBool() to inspect the returned value

Before fix:
getBool() returns null instead of false.

After fix:
getBool() correctly returns false.

The same issue can be reproduced for:

  • getNumber() when a stored value is 0
  • getString() when a stored value is ""

Screenshots

N/A — logic-only change with no UI impact.

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

All three getter methods shared the same || null pattern, so the fix applies consistently across them.

While some current callers use ?? fallbacks that mask this issue, the underlying behavior is still incorrect and could affect future usages where no fallback is applied.

This update ensures correct handling of falsy preference values and aligns the implementation with the expected behavior of MMKV getters (undefined meaning “key not found”).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed user preference handling to correctly preserve falsy values (empty strings, false, and 0) when retrieving stored preferences.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

Walkthrough

Fixed a bug in user preferences where the logical OR operator (||) was incorrectly converting falsy values (false, 0) to null when reading stored preferences. Replaced with nullish coalescing operator (??) to properly distinguish between missing keys and stored falsy values across three getter methods.

Changes

Cohort / File(s) Summary
User Preferences Value Normalization
app/lib/methods/userPreferences.ts
Fixed getString, getBool, and getNumber methods to use nullish coalescing (??) instead of logical OR (`

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A carrot's worth of code, so small and neat,
False and zero hop with bunny feet,
No longer lost to null's cruel snare,
True values dance through the MMKV air!

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: preventing falsy values (false, 0, empty strings) from being coerced to null, which directly addresses the core issue in the changeset.
Linked Issues check ✅ Passed The changes directly satisfy all requirements from #6983: getString/getBool/getNumber now use explicit undefined checks instead of || null, preserving falsy values while mapping missing keys to null.
Out of Scope Changes check ✅ Passed All changes in userPreferences.ts are directly related to fixing the falsy value handling in the three getter methods specified in #6983; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into develop

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


No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 757ea73 and 7016d12.

📒 Files selected for processing (1)
  • app/lib/methods/userPreferences.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: ESLint and Test / run-eslint-and-test
🔇 Additional comments (3)
app/lib/methods/userPreferences.ts (3)

101-102: LGTM — correctly preserves empty-string values.

The explicit undefined check properly distinguishes a missing key from a stored "".


114-115: LGTM — correctly preserves false values.


144-145: LGTM — correctly preserves 0 values.

✏️ Tip: You can disable this entire section by setting review_details to false in your review 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant