-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix IDBKeyVal get returning undefined instead of null #408
Conversation
lib/storage/providers/IDBKeyVal.js
Outdated
@@ -102,7 +102,7 @@ const provider = { | |||
* @param {String} key | |||
* @return {Promise<*>} | |||
*/ | |||
getItem: key => get(key, getCustomStore()), | |||
getItem: key => get(key, getCustomStore()).then(val => (val != null ? val : null)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to your explanation, shouldn't this check if the value is undefined, and if so, return null? This change looks like the ternary isn't doing anything and is the same thing as returning the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will check for null / undefined double =
and return null
in both cases, I could change the check to === undefined
if you think it is clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good shout, I think given the explanation and RCA, checking for ===
undefined would be cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please. Our styles prefer strict comparison. Could you also please add a comment to the code that the purpose for this logic is to make the storage APIs consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
I'm getting some unexpected report preview loading behaviour when testing this PR (but probably stemming from #401), as well as the RHP generally rendering less snappily: chrome-desktop-2023-10-30_12.23.39.mp4Note that the IOU preview and header aren't rendering at the same time. Compare with v1.0.107: chrome-desktop-2023-10-30_12.57.20.mp4 |
@jjcoffee Do you know if this happens only on this PR and not on main? Or is it a regression since 1.0.107? |
It looks like a regression since 1.0.107. |
👍 I think we can go ahead with this then, I can have a look at that issue tomorrow. @tgolen any idea what could have caused that? |
Sorry! I don't have any ideas what can be causing that, but it sounds like we are OK to merge this. |
Co-authored-by: Tim Golen <tgolen@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@mountiny would you approve and merge this, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for digging into this!
Details
getItem
is supposed to return null when the value doesn't exist in storage. This is what the native sqlite storage implementation does, as well as what the function documentation says. However https://github.com/jakearchibald/idb-keyval#get returns undefined when the value doesn't exist so we need to convert it to null.This caused some issues where some components would stay stuck in loading state because in onyx we assume undefined means the key value has not been loaded from storage, non-existing keys are represented by null. The issue was reported here Expensify/App#29169 (comment).
Related Issues
Expensify/App#29169
Automated Tests
N/A
Manual Tests
Tested in Expensify app with Expensify/App#29169. On web, opening settings will cause a blank screen to open. After this fix it loads properly.
Author Checklist
### Related Issues
section aboveTests
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
Mobile Web - Chrome
Before:
After:
Mobile Web - Safari
Desktop
iOS
Android