[PR 5 of 16] Remove global Onyx reference from getOriginalReportID#82864
[PR 5 of 16] Remove global Onyx reference from getOriginalReportID#82864
Conversation
|
@situchan Would you be available to review this? |
| }); | ||
|
|
||
| function clearReportActionErrors(reportID: string, reportAction: ReportAction, keys?: string[]) { | ||
| const originalReportID = getOriginalReportID(reportID, reportAction, undefined); |
There was a problem hiding this comment.
This is the call I was able to remove in this PR
| if (report?.parentReportID && report?.parentReportActionID && ignore !== 'parent') { | ||
| const parentReportAction = getReportAction(report.parentReportID, report.parentReportActionID); | ||
| const parentErrorKeys = Object.keys(parentReportAction?.errors ?? {}).filter((err) => errorKeys.includes(err)); | ||
| const parentReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`] ?? {}; |
There was a problem hiding this comment.
I know it stinks to have to add this (and the one a few lines below). I fully intend to pass these as params in the next PR. I felt it was just too much to do it in this same PR.
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
yes thanks |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22f435e994
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| clearAllRelatedReportActionErrors(reportID, action); | ||
| }, [action, isSendingMoney, clearAllRelatedReportActionErrors, reportID, allReports, report, clearError]); | ||
| clearAllRelatedReportActionErrors(reportID, action, originalReportID); |
There was a problem hiding this comment.
Default unresolved originalReportID to the current report
This call now forwards originalReportID directly, but useOriginalReportID() can return undefined when the action is not found in the current Onyx slice (and this component also defaults missing values to '-1'). In those cases clearAllRelatedReportActionErrors() ultimately writes to REPORT_ACTIONSundefined/REPORT_ACTIONS-1 instead of the real report action collection, so dismissing an error can leave brick-road errors and optimistic actions uncleared. Please fall back to reportID (or recompute via getOriginalReportID) before invoking the clear/cleanup paths.
Useful? React with 👍 / 👎.
|
|
||
| const [isLoading, setIsLoading] = useState(true); | ||
| const parentReportAction = report?.parentReportActionID ? parentReportActions?.[report.parentReportActionID] : undefined; | ||
| const originalReportID = useOriginalReportID(report?.reportID, parentReportAction); |
There was a problem hiding this comment.
Is the logic of this hook exactly same as getOriginalReportID function?
It's possible that this hook might return undefined for some reason, while getOriginalReportID always returns reportID as fallback.
App/src/hooks/useOriginalReportID.ts
Lines 73 to 74 in 9a0afa0
The bot raised the same concern here.
There was a problem hiding this comment.
I had the exact same question! I found the original author of the hook, and we discussed that the logic in the hook is probably more accurate than the method. We discussed a plan to try to unify the method and hook more (by just having the server return the reportAction.reportID and being able to reference that directly without as much of the extra logic), but I don't know when we'll be able to do that.
I'm not too worried about this returning undefined because I think it will only happen in theory and never in practice. If we are really worried about it, then I could add a log line so that we are at least aware if it is returning undefined.
|
No product review needed |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariScreen.Recording.2026-02-19.at.11.20.56.PM.mov |
|
There's conflict |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4060a624f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| clearAllRelatedReportActionErrors(reportID, action); | ||
| }, [action, isSendingMoney, clearAllRelatedReportActionErrors, reportID, allReports, report, clearError]); | ||
| clearAllRelatedReportActionErrors(reportID, action, originalReportID); |
There was a problem hiding this comment.
Fall back to reportID when clearing action errors
dismissError now forwards originalReportID directly, but useOriginalReportID() can legitimately return undefined when the action cannot be resolved yet (e.g., merged/single-transaction threads before related actions are loaded). In that case this path calls clearAllRelatedReportActionErrors() with an unknown origin, and clearReportActionErrors() writes to a non-report key instead of the action’s real report, so dismissing a failed money request can leave the red-brick error/optimistic action uncleared. Before this change, clearAllRelatedReportActionErrors() computed the origin internally and fell back to reportID.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4060a624f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
|
|
||
| clearReportActionErrors(reportID, reportAction, keys); | ||
| clearReportActionErrors(reportID, reportAction, originalReportID, keys); |
There was a problem hiding this comment.
Fallback to reportID when original report ID is unresolved
clearAllRelatedReportActionErrors() now forwards the caller-provided originalReportID directly, but new callers source it from useOriginalReportID(), which explicitly returns undefined when it cannot resolve the action yet (src/hooks/useOriginalReportID.ts). In that case this path can write to an invalid key (REPORT_ACTIONSundefined/sentinel values) instead of the real report’s actions, so dismissing errors does not clear the actual red-brick-road state. Before this change, getOriginalReportID() was recomputed internally and fell back from reportID, so this regression appears only after this refactor.
Useful? React with 👍 / 👎.
| new Promise<void>((resolve) => { | ||
| if (iouReportID) { | ||
| clearAllRelatedReportActionErrors(iouReportID, iouAction ?? null); | ||
| clearAllRelatedReportActionErrors(iouReportID, iouAction ?? null, iouReportID); |
There was a problem hiding this comment.
@tgolen should this new arg be the same iouReportID?
There was a problem hiding this comment.
Yep, it's the same value that getOriginalReportID() would return, so it's fine to just short-cut the test and use the value. I could add a call to getOriginalReportID() in this test, but I don't think there is too much value in it since that method already has unit tests covering it.
grgia
left a comment
There was a problem hiding this comment.
The comments you added were useful for review, thanks! NAB comment as I'm fairly sure that test scenario doesn't include a thread/move, but double checking
|
🚧 @tgolen has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/tgolen in version: 9.3.25-0 🚀
|
|
🚀 Deployed to production by https://github.com/puneetlath in version: 9.3.25-13 🚀
|
Explanation of Change
This is part of the process to remove a global reference from
getOriginalReportID()(18 references). Here is the full refactoring plan:reportActionsParamparameter and fallback to the global Onyx value forallReportActionsundefinedfor the parameterreportActionsavailable to pass that as the parameterreportActionsas the parameterreportActionsParamtoreportActionsallReportActionsand the Onyx connectionFixed Issues
Part of #66419
Tests
Offline tests
Same as tests
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)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: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari