[CP Staging] fix: prevent app crash in group chat when going back online#54652
Conversation
src/pages/ReportDetailsPage.tsx
Outdated
| // eslint-disable-next-line rulesdir/no-default-id-values | ||
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID ?? ''}`); | ||
| // eslint-disable-next-line rulesdir/no-default-id-values | ||
| const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? ''}`); |
There was a problem hiding this comment.
Should we use CONST.DEFAULT_NUMBER_ID as the defaults here? Or is '' better?
There was a problem hiding this comment.
using CONST.DEFAULT_NUMBER_ID also breaks the app because key is dynamically changed from report_ to report_0. I think using '' is the only safe way here
There was a problem hiding this comment.
Interesting! I am surprised b/c we use CONST.DEFAULT_NUMBER_ID so often, even for the report ID like here:
I am very ok with keeping this '' for now, but I think we'll eventually want a better solution OR we should make eslint accept default to an empty string (again, later / not in this PR), what do you think? :D
There was a problem hiding this comment.
I think ideally in the future we could align the shape of optimistic report with the one that comes from OpenReport endpoint - we optimistically create it with parentReportID as empty string and then we receive null in a response. This might require a change on the backend
I'm tagging @VickyStash to answer allowing empty string as default question, as she has much more context of this rule than me 😅
There was a problem hiding this comment.
Innnteresting! Ok so how about for now, since your solution should work, let's get it merged & CP'd so we can unblock deploy, then we can figure out "the best solution" as a follow-up?
There was a problem hiding this comment.
It looks like somewhere in the app the parentReportID is optimistically set to empty string ''.
So this way the hook
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`);
tries to get the data using firstly
report_ key - the whole collection key
report_undefined key - specific report key
Since one useOnyx hook is used to get both collection and specific item it gives error.
For the same reason the nullish coalescing rule was disabled before.
Ideally, we should find out why parentReportID is turned into a string and prevent it. But we discussed it with @TMisiukiewicz and it looks like it can have side effects at this stage.
For now, we can also check specifically if parentReportID is not an empty string or turn it back to as it was before (@shubham1206agra mentioned below).
src/pages/ReportDetailsPage.tsx
Outdated
| // eslint-disable-next-line rulesdir/no-default-id-values | ||
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID ?? ''}`); | ||
| // eslint-disable-next-line rulesdir/no-default-id-values | ||
| const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? ''}`); |
There was a problem hiding this comment.
| // eslint-disable-next-line rulesdir/no-default-id-values | |
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID ?? ''}`); | |
| // eslint-disable-next-line rulesdir/no-default-id-values | |
| const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? ''}`); | |
| /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ | |
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || CONST.DEFAULT_NUMBER_ID}`); | |
| const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || CONST.DEFAULT_NUMBER_ID}`); |
Lets do the original way.
There was a problem hiding this comment.
Ooh yeah if we end up with this:
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}`);
Will that subscribe to the entire collection? That sounds baaaad
There was a problem hiding this comment.
I guess something like this should work as well:
This way we can get rid of nullish-coalescing disable
const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.parentReportID === '' ? undefined : report?.parentReportID}`);
src/pages/ReportDetailsPage.tsx
Outdated
| // eslint-disable-next-line rulesdir/no-default-id-values | ||
| const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.parentReportID ?? ''}`); |
There was a problem hiding this comment.
| // eslint-disable-next-line rulesdir/no-default-id-values | |
| const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.parentReportID ?? ''}`); | |
| const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.parentReportID || CONST.DEFAULT_NUMBER_ID}`); | |
| /* eslint-enable @typescript-eslint/prefer-nullish-coalescing */ |
Beamanator
left a comment
There was a problem hiding this comment.
@TMisiukiewicz I think @shubham1206agra is right that we can't default to empty strings, because that would subscribe to entire collections - can you please help us get this updated quick so we can test & merge to fix the deploy blocker?
|
good catch - I think my mind is still somewhere in a Christmas season 😆 thanks for help everyone! |
| /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ | ||
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || CONST.DEFAULT_NUMBER_ID}`); |
There was a problem hiding this comment.
Maybe we can also get rid of nullish-coalescing disable, but it's up to you
| /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ | |
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || CONST.DEFAULT_NUMBER_ID}`); | |
| const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID === '' ? undefined : report.parentReportID}`); |
|
@VickyStash won't the |
I've explained it here. |
|
Aah true, thanks for pointing that out 👍 But even if I would prefer going with @shubham1206agra 's suggestion for now instead of possibly using |
Reviewer Checklist
Screenshots/VideosAndroid: NativeScreen.Recording.2024-12-30.at.6.37.04.PM.movAndroid: mWeb ChromeiOS: NativeScreen.Recording.2024-12-30.at.6.31.01.PM.moviOS: mWeb SafariScreen.Recording.2024-12-30.at.6.23.34.PM.movMacOS: Chrome / SafariScreen.Recording.2024-12-30.at.6.21.46.PM.movMacOS: DesktopScreen.Recording.2024-12-30.at.6.26.13.PM.mov |
|
I think we should look into "where we set |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
…oup-chat fix: prevent app crash in group chat when going back online (cherry picked from commit 9debee9) (CP triggered by Beamanator)
|
🚀 Cherry-picked to staging by https://github.com/Beamanator in version: 9.0.79-5 🚀
@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes. |
|
🚀 Deployed to production by https://github.com/puneetlath in version: 9.0.79-5 🚀
|
Explanation of Change
When going back online, the app was crashing because once the optimistic report was created, the shape of the report was changing, and it was dynamically change Onyx key from
report_toreport_undefined. We need to bring back the fallback to empty string inReportDetailsPageto avoid dynamically subscribing to entire collection.Couldn't record videos on mobile web as I haven't found any way to open debug modal on a simulator
Fixed Issues
$ #54595
PROPOSAL:
Tests
Offline tests
n/a
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
android.mov
Android: mWeb Chrome
iOS: Native
ios.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov