Repository navigation
Remove unsafe assertions from search, domain, hold, and per diem flows - #103895
Conversation
Seatbelt-Operation: 593570c7-465b-4e60-836c-0bbaedbef4c6
Seatbelt-Operation: 3977d0cd-ed13-4370-833c-8df981994e39
|
@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| }); | ||
| const wrapperBorderColorAnimatedStyle = useAnimatedStyle(() => { | ||
| const borderColors = [wrapperBorderColor, focusedBorderColor].map((color) => { | ||
| processColor(color); |
There was a problem hiding this comment.
❌ CONSISTENCY-18 (docs)
The standalone processColor(color); call discards its return value, so at a glance it reads as dead code. Its actual purpose is non-obvious: processColor throws on invalid color input, so this call exists only to surface that error eagerly for every endpoint (the test uses the default border and preserves endpoint error order until worklet execution relies on it throwing 'first-invalid'). Nothing in the surrounding code reveals that intent, and the adjacent comment only explains the later convertToRGBA coercion, not this call.
Add a comment explaining why the result is intentionally ignored, e.g.:
const borderColors = [wrapperBorderColor, focusedBorderColor].map((color) => {
// Validate each endpoint up front so an invalid color throws here, preserving the original error order.
processColor(color);
if (typeof color === 'string') {
return color;
}
...
});Reviewed at: 957eaa2 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
There was a problem hiding this comment.
Removed the unused processColor call and the redundant color conversion. String colors pass through; opaque colors fall back to the active theme's border color.
Reviewer Checklist
Screenshots/VideosScreen.Recording.2026-10-17.at.17.46.05.mov |
| const newTransaction: OnyxTypes.Transaction = { | ||
| // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style | ||
| ...(transaction as OnyxTypes.Transaction), | ||
| const newTransaction: NonNullable<OnyxSetInput<typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT>> = { |
There was a problem hiding this comment.
src/libs/actions/IOU/PerDiem.ts L88 / L121 / L158
🟠 Removing the cast exposes what ...transaction does when transaction is undefined: we still call Onyx.set with a partial object on transactionsDraft_undefined. The new test in tests/actions/IOU/PerDiemTest.ts L142/L182 now asserts that junk key gets written, so the bug becomes expected behavior.
Can we return early in all 3 functions instead ?
if (!transaction) {
return;
}
const newTransaction: OnyxTypes.Transaction = {
...transaction,
// ...
};That also lets newTransaction stay OnyxTypes.Transaction (no NonNullable<OnyxSetInput<...>> copied 3 times), and the test can assert Onyx.set was never called.
As it stands, any per diem rate edit that runs before the draft loads creates an orphan transactionsDraft_undefined entry that never gets cleaned up.
There was a problem hiding this comment.
Added an early return to all three per-diem editors when the transaction is missing, before any Onyx write. Kept normal Transaction types for valid edits and added checks that no orphan transaction is created.
| const parsedAutocomplete = parse(input) as SearchAutocompleteResult; | ||
| const parsedAutocomplete: unknown = parse(input); | ||
| if (!isAutocompleteParserResult(parsedAutocomplete)) { | ||
| throw new Error('Invalid autocomplete parser result'); |
There was a problem hiding this comment.
src/libs/SearchAutocompleteUtils.ts L340
🟠 parseForLiveMarkdown is the live-markdown worklet parser, and live-markdown doesn't wrap custom parsers in a try/catch. If this new guard ever fails, we throw on the UI thread on every keystroke in the Search input, which crashes native.
Since we're adding the shape check, let's degrade gracefully and skip highlighting:
if (!isAutocompleteParserResult(parsedAutocomplete)) {
return [];
}There was a problem hiding this comment.
Changed an invalid parser-result shape to return an empty highlight list, so it does not introduce a new worklet exception. The existing parser's own exception behavior is unchanged.
| const allTransactions = getAllTransactions(); | ||
| const iouReportActions = getAllReportActions(reportID); | ||
| const holdReportActions: Array<OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU>> = []; | ||
| const holdReportActions: OnyxTypes.ReportAction[] = []; |
There was a problem hiding this comment.
src/libs/actions/IOU/Hold.ts L635
🟡 Widening holdReportActions to OnyxTypes.ReportAction[] throws away the IOU type for every consumer of getHoldReportActionsAndTransactions, so getOriginalMessage(holdReportAction) now returns the union of every original message type.
We can narrow up front with the existing guard and keep the original type, with no cast:
const holdReportActions: Array<OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU>> = [];
for (const action of Object.values(iouReportActions)) {
if (!isMoneyRequestAction(action)) {
continue;
}
const transactionID = getOriginalMessage(action)?.IOUTransactionID;
// ...Behavior is the same, because a non-IOU action already resolves to no transaction and hits continue.
There was a problem hiding this comment.
Moved the existing IOU action guard before transaction lookup and kept the returned hold actions typed as IOU actions. Added coverage for a non-IOU action without widening the return type.
| const borderColors = [wrapperBorderColor, focusedBorderColor].map((color) => { | ||
| processColor(color); | ||
| if (typeof color === 'string') { | ||
| return color; | ||
| } | ||
|
|
||
| // Interpolation coerces opaque colors to zero channels. Keep that behavior and the literal transparent marker on string endpoints. | ||
| const [red, green, blue, alpha] = convertToRGBA(color); | ||
| return `rgba(${Math.round(red * 255)}, ${Math.round(green * 255)}, ${Math.round(blue * 255)}, ${alpha})`; |
There was a problem hiding this comment.
src/components/Search/SearchAutocompleteInput.tsx L134-142
🟡 Besides the bot's point: convertToRGBA already runs the color through processColorInitially itself, so the separate processColor(color) adds nothing. In practice both endpoints are theme strings anyway (theme.border or ViewStyle overrides from callers). Can we simplify to a string check ?
const toBorderColor = (color: ColorValue) => (typeof color === 'string' ? color : defaultBorderColor);
// ...
borderColor: interpolateColor(focusedSharedValue.get() ? 1 : 0, [0, 1], [toBorderColor(wrapperBorderColor), toBorderColor(focusedBorderColor)], 'RGB'),This drops the processColor/convertToRGBA imports and the hand-built rgba(...) string. An opaque PlatformColor would then fall back to the default border instead of the current transparent black.
There was a problem hiding this comment.
Simplified the interpolation inputs: keep string colors as supplied and use the current theme border for opaque colors. Removed both conversion calls. Tests check the installed interpolation behavior and dark-theme fallback.
| // If the transaction thread report wasn't created before, we create it optimistically | ||
| if (!initialReportID) { | ||
| if (createdThread) { | ||
| const transactionThreadReport = createdThread; |
There was a problem hiding this comment.
src/libs/actions/IOU/Hold.ts L235
🟢 Nit: const transactionThreadReport = createdThread; is just an alias. Can we use createdThread directly in this block ?
There was a problem hiding this comment.
Removed the redundant transactionThreadReport alias and used createdThread directly in that block.
|
@KJ21-ENG PR has no blockers but needs changes: I'd ask for 4 fixes and 1 nit - posted above ☝️ The bots have already covered the standalone The rest of the diff looks fine: the Domain membership objects built by assignment, the Please tag me once addressed 🙌 |
|
PR doesn’t need product input as a refactor PR. Unassigning and unsubscribing myself. |
Seatbelt-Operation: reviewer-fix-103895-400f83b6-66e0-4864-aee1-52ef51a6f153
|
@ikevin127 Could you please check this once you get a chance, Thanks! |
ikevin127
left a comment
There was a problem hiding this comment.
🟢 LGTM - The author pushed one commit (6f93a93) that fixes all 6 of my threads plus the bot's processColor thread, but the Explanation of Change now understates two behavior changes.
@KJ21-ENG I won't block on it but it will be good to have it state the behaviour changes correctly:
PR description, Explanation of Change
🟡 "Membership, Hold and per diem updates retain their existing data operations" isn't accurate anymore. Can we update it to say that:
- the per diem subrate editors now skip the draft write when the transaction is missing (no more
transactionsDraft_undefined); - moving held expenses only selects IOU actions;
- opaque platform border colors in the Search input fall back to the theme border
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 blimpich 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! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/blimpich in version: 9.5.15-1 🚀
|
|
No help site update is needed: this PR only replaces unsafe type assertions with type guards in Search, Domain, Hold, and Per diem code, so no feature, label, or documented behavior changes for users. |
|
🚀 Deployed to production by https://github.com/grgia in version: 9.5.15-3 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Remove unsafe assertions from search, domain membership, Hold and per diem actions. Search validates the generated parser fields consumed by autocomplete and highlighting, and keeps border/ref handling typed. SCIM success responses keep every string token, including the empty string; missing or non-string tokens enter the existing error/retry state. Membership, Hold and per diem updates retain their existing data operations.
Fixed Issues
$ #94739
PROPOSAL: #94739 (comment)
Tests
Checked-in parser, search-input, domain and expense-action tests cover the changed boundaries. The focused run passed 439 tests in ten suites; current upstream test jobs, lint and typecheck passed. Action tests cover malformed SCIM responses with the existing error/retry renderer unchanged.
Platforms: web, mWeb and native, including iOS for Search border interpolation and live highlighting.
Search input
Setup: Use a signed-in account with Search access.
merchant:"Acme\,Inc". Verify the escaped value highlights without an input error.columns:date. Verifydatehighlights as valid.columns:unknown-column. Verify the unknown value stays unhighlighted and typing remains responsive.Hold
Setup: Open an eligible expense's existing thread with Hold available.
Offline tests
Setup: Load the eligible expense and its existing thread while connected.
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, 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.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Recordings (2)
Recording 1 shows Windows Chrome Search focus, clearing, escaped-merchant and column highlighting. Recording 2 shows Hold and Remove hold in an existing thread, with an obstructed submit label. Console errors were observed without confirmed attribution to this PR. Native/mobile/Safari and offline reconnect results are unverified.
01-search-focus-highlighting-desktop.mp4
02-hold-remove-desktop.mp4