Repository navigation
refactor: remove unsafe assertions from router history, duplicate merging and bank lookups - #102986
Conversation
…n types Seatbelt-Operation: session4-sign-28673b16-6202-4c89-baec-1773e1dedf28
Seatbelt-Operation: session4-corrected-sign-b69973f5-49aa-4f55-b41a-dfcdc1d1c3a7
Seatbelt-Operation: remaining-102986-sign-35ae4f8f-bb11-4640-a2dc-ce2aed4c9faa
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
Seatbelt-Operation: main-20261030-102986-sign-7c520341-4f79-4712-b2ac-e1b4eedb3664
Resolve the TransactionUtils conflicts by widening the moved field helpers. Revert the helper renames and keep the history tests as on main.
|
@situchan, could you please review this PR? Merged |
Codex Review Summary: ✅ CompletedThis 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. |
| function preserveHistoryForRoutes(oldHistory: unknown[], routes: Array<{key?: string}>): unknown[] { | ||
| const remainingKeys = new Set(routes.map((r) => r.key)); | ||
| return oldHistory.filter((entry) => typeof entry === 'string' || remainingKeys.has(entry.key)); | ||
| // Keep history sentinels and anything that is not a route snapshot; drop only route snapshots whose route is gone. |
There was a problem hiding this comment.
❌ CONSISTENCY-16 (docs)
This newly added comment uses the banned term "sentinels". Per CONSISTENCY-16, prefer plain language such as "guard entries" / "markers" in authored comments.
Suggested fix:
// Keep history guard entries and anything that is not a route snapshot; drop only route snapshots whose route is gone.
return oldHistory.filter((entry) => !isRecord(entry) || typeof entry.key !== 'string' || remainingKeys.has(entry.key));Note: this is low-confidence, since sentinel is already established terminology in these files (isModalHistorySentinel, getTrailingStringSentinels, etc.) that this PR keeps.
Reviewed at: b71a6f0 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
Fixed in cf90f6c. The comment now says "string history markers". I kept the existing isModalHistorySentinel and related function names, because this PR does not add them.
JmillsExpensify
left a comment
There was a problem hiding this comment.
No product review required.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safaritest1.movtest2.mov |
| function rehydrate(newState: PartialState<RootHistoryState> | RootHistoryState, configOptions: RouterConfigOptions) { | ||
| return getRehydratedState(newState as PartialState<RootHistoryState>, configOptions); | ||
| return getRehydratedState(newState, configOptions); | ||
| } |
There was a problem hiding this comment.
rehydrate now only forwards to getRehydratedState
rehydrate existed to hold the cast to PartialState. With the cast gone and getRehydratedState taking PartialState | RootHistoryState, both have the same signature.
Can we remove rehydrate and pass getRehydratedState at its four call sites?
|
✋ 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.53-0 🚀
|
|
No help site update needed — this PR is an internal type-safety refactor that adds no user-facing functionality and leaves existing documented workflows unchanged. |
|
This PR failing because of the issue #107807 |
|
#107807 is not caused by this PR. The bug was already in production.
This PR only replaced type casts around that code. @jponikarchuk, could you please mark this PR as not failing for this issue? |
|
🚀 Deployed to production by https://github.com/arosiclair in version: 9.5.53-3 🚀
Bundle Size Analysis (Sentry): |
1 similar comment
|
🚀 Deployed to production by https://github.com/arosiclair in version: 9.5.53-3 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Remove unsafe
ascasts from router history, duplicate merging and bank connection lookups.addPushParamsRouterExtension,addRootHistoryRouterExtension,addRootHistoryRouterExtensionUtils,useSyncSidePanelWithHistory): React Navigation typeshistoryasunknown[]. TheasCustomHistoryhelper and theas CustomHistoryEntry[]/as NavigationRoutecasts are gone. The helpers now takeunknown[]and check each entry at runtime:typeof entry === 'string'for back-guard entries andisRecord(entry)for route snapshots.getRehydratedState: React Navigation'sRouter.getRehydratedStateaccepts a partial or a full state. Our wrappers now accept both too, so theas PartialStatecast and the@ts-expect-errorare gone. Therehydratewrapper only held that cast, so it is removed and its callers usegetRehydratedStatedirectly.removeSettledAndApprovedTransactions: the filter is a type guard (transaction is Transaction), so theas Transaction[]is gone.compareDuplicateTransactionFields:'modifiedMerchant'and'merchant'are already keys ofTransaction, so theiras keyof Transactioncasts are removed.buildMergeDuplicatesParamspasses aPartial<Transaction>.getAmount,getCurrency,getCreated,getFormattedCreatedandhasValidModifiedAmountnow accept the partial fields they read, so theas OnyxEntry<Transaction>casts are gone.getCompanyCardBankConnection/getPersonalCardBankConnection:getObjectKeysgives typed bank keys, andhasKeychecks the key exists inBANK_CONNECTIONS.BANKShas keys such asOTHERthat have no connection, and those still giveundefined.No behavior change. The app writes every history entry itself, so the new runtime checks pass for every entry it stores.
Changed files
src/components/SidePanel/useSyncSidePanelWithHistory/index.tssrc/libs/Navigation/AppNavigator/routerExtensions/addPushParamsRouterExtension.tssrc/libs/Navigation/AppNavigator/routerExtensions/addRootHistoryRouterExtension.tssrc/libs/Navigation/AppNavigator/routerExtensions/addRootHistoryRouterExtensionUtils.tssrc/libs/TransactionUtils/amountUtils.tssrc/libs/TransactionUtils/duplicates.tssrc/libs/TransactionUtils/fields.tssrc/libs/actions/getCompanyCardBankConnection/index.tsxFixed Issues
$ #94739
PROPOSAL: #94739 (comment)
Tests
C01 Tab history and layout changes
Precondition: On web, use a browser window narrower than 800 px. On Android, use the app. Open Spend > Expenses. Skip this case on iOS native, because the Spend tab has no Back action there.
C02 Expense editor, close order, and focus
Precondition: Open an existing expense in its chat.
C03 Desktop side-panel resize
Precondition: Web in a computer browser, window wider than 1300 px.
C04 Merge duplicate expenses
Precondition: You created two workspace expenses with the same amount, merchant and date in your own draft report, and they are flagged as duplicates.
C05 Company card bank connection
Precondition: You are an admin of a workspace with Company cards enabled. On Collect, the workspace has no company card feed yet.
No new tests are added, because each cast removal keeps the same behavior.
tests/unit/Navigation/routerExtensions/addPushParamsRouterExtension.test.ts,tests/unit/Navigation/routerExtensions/addRootHistoryRouterExtension.test.ts,tests/unit/TransactionUtilsTest.ts,tests/actions/IOUTest/DuplicateTest.tsandtests/unit/GetCompanyCardBankConnectionTest.tscover the changed code.Offline tests
N/A. These history, field and lookup changes do not change requests, queues, stored data or reconnect handling.
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
Screenshots/Videos (6)
C01 phone-sized
PR-102986-C01-M.mp4
C02 desktop
102986-C02-desktop.mp4
C02 phone-sized
102986-C02-phone-sized.mp4
C03 desktop
102986-C03-desktop.mp4
C04 desktop
102986-C04-desktop.mp4
C05 desktop
102986-C05-desktop.mp4