[BE] Company Cards - Imported cards are not displayed until multiple page refreshes
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 9.3.61-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/88136 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Windows 11 App Component: Other
Action Performed:
1.Go to Workspace → Company Cards 2.Click Add cards 3.Select United States → Next 4.Select Direct feed → Next 5.Select Import transactions from file → Next 6.Enter Company card layout name and save it 7.Click Next 8.Upload a valid CSV file 9.Map Account number to Card number 10.Click Import
Expected Result:
Imported cards are displayed immediately after the import process is completed
Actual Result:
Imported cards are not displayed after the import Cards only appear after refreshing the page
Workaround:
Unknown
Platforms:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [ ] MacOS: Chrome / Safari
Screenshots/Videos
https://github.com/user-attachments/assets/0283d1d5-2614-4c0a-8708-df4930fe071b
Issue Owner
Current Issue Owner: @grgiaUpwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022046743541008094774
- Upwork Job ID: 2046743541008094774
- Last Price Increase: 2026-06-24
Proposal
What is the root cause of that problem?
After the CSV import completes, importCSVCompanyCards in CompanyCards.ts:1225-1240 only updates ONYXKEYS.IMPORTED_SPREADSHEET in its successData (to show the success modal). It does not trigger a re-fetch of the card feed data.
When the user navigates back to the Company Cards page, the useEffect in WorkspaceCompanyCardsPage.tsx:68-74 skips calling openPolicyCompanyCardsPage because hasFeedsLoaded is already true — the feed data was loaded during the initial visit. So the page displays stale data and the newly imported cards don't appear until the user manually refreshes.
What changes do you think we should make in order to solve the problem?
After the import succeeds and the user dismisses the success modal (navigating back to the Company Cards page), the page should re-fetch the card feed data from the server. The simplest fix is to call openPolicyCompanyCardsFeed when navigating back from the import flow, ensuring the latest card list is loaded. This could be done by:
- Adding a
successDataupdate inimportCSVCompanyCardsthat sets a flag (e.g., on the card feed's Onyx key) indicating data needs refreshing, OR - Calling
openPolicyCompanyCardsFeedfrom the navigation callback inCompanyCardsImportedPagewhen the success modal is dismissed, so the card data is explicitly re-fetched before/when the user lands back on the Company Cards page.
What alternative solutions did you explore? (Optional)
An alternative would be to modify the hasFeedsLoaded guard in WorkspaceCompanyCardsPage to also account for a "stale" state after imports, but this would add complexity to the page component for a condition that only applies post-import. Triggering the re-fetch at the source (import completion) is cleaner.
Supporting evidence
successDataonly updates the modal state:CompanyCards.ts:1225-1240— the onlysuccessDataentry updatesONYXKEYS.IMPORTED_SPREADSHEETto show the success modal. No card feed or card list keys are updated.- Page guard prevents re-fetch:
WorkspaceCompanyCardsPage.tsx:66-74—hasFeedsLoadedistruebecauseallCardFeedsalready has data from the initial page load, soloadPolicyCompanyCardsPage()is never called again. - Optimistic data is insufficient:
CompanyCards.ts:1321-1335— optimistic data adds card name strings tocardListbut these are just{cardName: cardName}entries, not fullCardobjects that render in the card table. - Navigation back has no refresh trigger:
CompanyCardsImportedPagecallsNavigation.goBack(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID))but nothing triggers a data refresh at that point.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @FitseTLT (External)
Job added to Upwork: https://www.upwork.com/jobs/~022046743541008094774
Proposal
Please re-state the problem that we are trying to solve in this issue.
Imported company cards are not immediately displayed after a successful import, requiring multiple page refreshes to appear.
What is the root cause of that problem?
The issue stems from how the card list is fetched using Onyx in useCompanyCards.ts (line 11). The useCardsList hook relies on selectedFeed to construct the Onyx key. If selectedFeed is initially undefined (which can happen during component mount or feed selection), the Onyx key will be incorrect, and the card list won't be retrieved from the correct location in Onyx. A page refresh resolves this by re-establishing the correct selectedFeed and thus the correct Onyx key.
What changes do you think we should make in order to solve the problem?
Provide a default value for the selectedFeed prop in the useCardsList hook. This ensures that the Onyx key is always constructed correctly, even when selectedFeed is initially undefined, preventing the need for a refresh to display the imported cards. The default value {domainID: '', feedName: ''} will ensure a valid key is generated.
What alternative solutions did you explore? (Optional)
N/A
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~2021935202864784599
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Compare branch with the fix: https://github.com/Expensify/App/compare/main...alexanderxfgl-bit/App:fix/88496-ai?expand=1
🚨 Edited by proposal-police: This proposal was edited at 2026-05-06 05:06:34 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
After importing company cards via CSV, the newly imported cards don't show up on the Company Cards page until the user refreshes multiple times.
What is the root cause of that problem?
importCSVCompanyCards() in CompanyCards queues its WRITE via API.write() (SequentialQueue), but when the user navigates back to the Company Cards page, loadPolicyCompanyCardsFeed in WorkspaceCompanyCardsPage calls openPolicyCompanyCardsFeed, which uses API.read() — and READs bypass the SequentialQueue, firing immediately. The server hasn't processed the import yet, so it returns stale/empty card data that overwrites WORKSPACE_CARDS_LIST.
The function also never writes optimistic entries to WORKSPACE_CARDS_LIST, so there's nothing for the user to see while the server catches up.
What changes do you think we should make in order to solve the problem?
Two changes in importCSVCompanyCards() in CompanyCards:
1. Write optimistic card entries to WORKSPACE_CARDS_LIST so cards appear immediately:
const uniqueCardNumbers = [...new Set(transactions.map((t) => t.cardName))];
const optimisticCardList = Object.fromEntries(
uniqueCardNumbers.map((cardNumber) => [cardNumber, cardNumber])
);
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${feedName}`,
value: {cardList: optimisticCardList},
});
2. Set pending: true on the feed in optimisticData, clear it in successData/failureData. The existing isFeedPending guard already skips openPolicyCompanyCardsFeed when the feed is pending — so once pending clears (meaning the server processed the WRITE), the READ fires and gets fresh data.
// optimisticData — suppress the premature READ
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`,
value: {settings: {companyCards: {[feedName]: {pending: true}}}},
});
// successData — allow READ now that server has the data
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`,
value: {settings: {companyCards: {[feedName]: {pending: null}}}},
});
// failureData — same
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`,
value: {settings: {companyCards: {[feedName]: {pending: null}}}},
});
Same pattern used by deleteWorkspaceCompanyCardFeed (lines 309-385). No new fields, refs, hooks, or UI changes — all done in the action layer.
What alternative solutions did you explore? (Optional)
MelvinBot's proposal (re-fetch after import): doesn't fix the timing — the READ still bypasses the SequentialQueue and can return stale data.
twilight2294's proposal (add WORKSPACE_CARDS_LIST to successData only): the stale READ fires independently and arrives after successData, so confirming optimistic data doesn't prevent the clobber.
wildan-m's proposal introduces a brand-new hasRecentLocalImport field on cardFeedsStatus plus finallyData with delay logic. Over-engineered — the pending field already exists on the feed type and isFeedPending already guards loadPolicyCompanyCardsFeed. No new state needed.
15antonian's proposal adds a useRef tracking isFeedAdded transitions in the page component. This puts the guard in the UI layer instead of the action layer, and couples the fix to component mount timing. Setting pending in the action keeps the logic where the import happens.
nabi-ebrahimi's proposal reads ADD_NEW_COMPANY_CARD in WorkspaceCompanyCardsPage — adds a new Onyx dependency to the page and couples the fix to the add-card flow state, which isn't semantically about "feed is pending." The pending field on the feed itself is the right semantic signal.
Proposal
Please re-state the problem that we are trying to solve in this issue.
After completing the "Import transactions from file" flow for Company Cards (Workspace → Company Cards → Add cards → Import transactions from file → upload CSV → map columns → Import), the imported cards are not displayed on the Company Cards page. The user has to refresh the page (sometimes multiple times) before the newly imported cards appear. PR https://github.com/Expensify/App/pull/88136 made the CSV feed itself render when it has no cards in Onyx, but it did not address the separate problem of the cardList disappearing right after a successful import — so the feed is shown, but it looks empty until the page is refreshed.
What is the root cause of that problem?
importCSVCompanyCards seeds the new unassigned cards optimistically into WORKSPACE_CARDS_LIST{workspaceAccountID}_{feedName}.cardList via a MERGE — but only inside optimisticData. When the write succeeds, the only successData entry is the spreadsheet modal flag; nothing in successData re-asserts the cardList:
https://github.com/Expensify/App/blob/1cff11f955165e8b1b0a73457ec23e110eff4178/src/libs/actions/CompanyCards.ts#L1321-L1337
https://github.com/Expensify/App/blob/1cff11f955165e8b1b0a73457ec23e110eff4178/src/libs/actions/CompanyCards.ts#L1225-L1240
Immediately after the success modal is dismissed, closeImportPageAndModal navigates back to WorkspaceCompanyCardsPage. That page mounts and the loadPolicyCompanyCardsFeed effect fires, which calls openPolicyCompanyCardsFeed for the newly-created CSV feed:
https://github.com/Expensify/App/blob/1cff11f955165e8b1b0a73457ec23e110eff4178/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx#L76-L86
https://github.com/Expensify/App/blob/1cff11f955165e8b1b0a73457ec23e110eff4178/src/libs/actions/CompanyCards.ts#L966-L1025
OpenPolicyCompanyCardsFeed's server response rewrites WORKSPACE_CARDS_LIST{domainID}_{feedName} with the feed's current server-side state. Because CSV imports are processed asynchronously on the backend (the write returns as soon as the import job is queued — which is why successData only updates the modal, not the cardList), the response that arrives moments later frequently does NOT yet include the cards that were just optimistically merged in. When that response replaces the cardList with a stale/empty set, useCompanyCards → buildCompanyCardEntries produces an empty array and the page falls through to WorkspaceCompanyCardsFeedAddedEmptyPage. Each manual refresh fires another openPolicyCompanyCardsFeed — eventually the backend finishes the import and the response contains the cards, so they finally show up ("multiple refreshes" is just whichever refresh wins the race with the backend job).
The cardList optimistic merge is there (it had to be, otherwise the cards would not flash in even briefly), but there is no mechanism that re-asserts it after a concurrent backend read clobbers it, so the imported cards vanish between the success modal and the moment the backend actually has them indexed.
What changes do you think we should make in order to solve the problem?
Teach the Company Cards page not to refetch a feed it has just populated via import, until the user actually intends to refresh.
In importCSVCompanyCards (src/libs/actions/CompanyCards.ts), add a transient "just imported" marker on the optimistic data — set cardFeedsStatus[feedName].isLoading: false and a new cardFeedsStatus[feedName].hasRecentLocalImport: true (or reuse an existing identifier if one fits) on the SHARED_NVP_PRIVATE_DOMAIN_MEMBER{workspaceAccountID} entry as part of the import's optimisticData. Clear the marker in a finallyData handler attached to the same write, gated on a short delay / next network-confirmed read of the feed so the marker lives long enough to cover the navigation back to the Company Cards page and the ensuing loadPolicyCompanyCardsFeed effect, but not indefinitely.
In WorkspaceCompanyCardsPage (src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx), extend loadPolicyCompanyCardsFeed's guard clause so that when the selected feed has the "just imported" marker set, the effect returns without calling openPolicyCompanyCardsFeed. The optimistic cardList from the import already reflects the correct set of new cards for the user to see, so skipping the immediate refetch avoids the race in which a stale server response overwrites the optimistic cardList with an empty one.
Also extend importCSVCompanyCards's successData to re-MERGE {cardList: mergedCardList} onto WORKSPACE_CARDS_LIST{workspaceAccountID}_{feedName}. Even with the refetch-skip guard above, this acts as a second line of defense: if any other code path (navigation-triggered fetch, Onyx garbage-collection, etc.) racially SETs the cardList after the optimistic merge, the import's successData will re-assert the imported card names once the backend acknowledges the write. The failureData already rolls back to existingCardsList ?? null, so adding a matching success-side merge keeps the pair symmetric.
The existing filter rules for CSV feeds added in PR #88136 (isCSVUploadFeed bypass in CardFeedUtils.getCombinedCardFeedsFromAllFeeds) keep the feed itself visible while the refetch is suppressed, so the feed will never vanish from the list — only the stale empty card payload is suppressed. On any user-initiated refresh (pull-to-refresh, network reconnect via useNetwork's onReconnect, or navigating away and back after the marker has expired), the normal openPolicyCompanyCardsFeed flow resumes and picks up the now-processed cards from the backend.
Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/88496-company-cards-import-refetch-race?expand=1
What alternative solutions did you explore? (Optional)
Asking the backend's OpenPolicyCompanyCardsFeed handler to MERGE rather than SET the cardList field would also resolve the clobber, since the optimistic card names would survive an empty server response. This is a cleaner fix at the source but requires a backend change; the frontend guard is what can be shipped from this repo and also protects against any other future caller of openPolicyCompanyCardsFeed that happens to race the import.
Adding a polling retry inside WorkspaceCompanyCardsPage — re-calling openPolicyCompanyCardsFeed every few seconds until the response includes cards — would also make the cards appear without a manual refresh, but it makes the race visible to the user as a loading flicker and adds unnecessary API load for every import; suppressing the first refetch while trusting the optimistic data is simpler and user-invisible.
⚠️ @wildan-m Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
Proposal updated — added compare branch with implementation.
@ProposalPolice this proposal identifies a different root cause than the referenced one. The referenced proposal attributes the bug to importCSVCompanyCards missing a WORKSPACE_CARDS_LIST entry in successData. My proposal identifies the subsequent openPolicyCompanyCardsFeed call (fired by WorkspaceCompanyCardsPage's mount effect) as the actual clobber — its response SETs WORKSPACE_CARDS_LIST with the backend's still-empty state (CSV import is processed asynchronously), which overwrites the optimistic cardList regardless of what importCSVCompanyCards's successData contains. The primary fix is a hasRecentLocalImport marker that causes loadPolicyCompanyCardsFeed to skip the refetch, not a successData re-merge. The referenced fix relies on importCSVCompanyCards's success arriving after openPolicyCompanyCardsFeed's response — a fragile ordering assumption; mine prevents the race entirely. The successData re-merge I mention is a secondary safety net, not the primary fix.
Proposal
What is the root cause of that problem?
The clobber happens inside WorkspaceCompanyCardsPage.tsx (src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx:84-86), not inside importCSVCompanyCards. This is a different race than earlier proposals identified.
When closeImportPageAndModal navigates back to the Company Cards page after a successful import, the page remounts and a useEffect calls loadPolicyCompanyCardsFeed → openPolicyCompanyCardsFeed. That API call's response does an Onyx SET (not MERGE) on WORKSPACE_CARDS_LIST{workspaceAccountID}_{feedName}.cardList. Because CSV imports are processed asynchronously on the backend (the API write returns as soon as the job is queued), the response that lands moments later typically does not yet contain the imported cards — so it overwrites the optimistic cardList with the backend's pre-import state. Each manual refresh fires another openPolicyCompanyCardsFeed; whichever one races past the backend job wins.
Adding WORKSPACE_CARDS_LIST to importCSVCompanyCards's successData (as prior proposals suggest) does not fix this, because openPolicyCompanyCardsFeed's response arrives independently and SETs the cardList. The success-data write only wins if it happens to land after the refetch response — a fragile ordering assumption.
What changes do you think we should make in order to solve the problem?
Guard the first post-import call to openPolicyCompanyCardsFeed using state already exposed by useCompanyCards. The hook returns isFeedAdded, which transitions false → true exactly when the imported feed appears in Onyx. We can key the guard off that transition:
In WorkspaceCompanyCardsPage.tsx, change loadPolicyCompanyCardsFeed so it skips the openPolicyCompanyCardsFeed call on the render where isFeedAdded just flipped from false to true and the optimistic cardList for that feed is non-empty. Track the prior value of isFeedAdded with a useRef. On every subsequent render — user-initiated refresh, useNetwork.onReconnect, future navigation back — the guard no longer applies and the normal refetch runs.
As a secondary safety net, also add a WORKSPACE_CARDS_LIST merge to successData in importCSVCompanyCards, mirroring deleteWorkspaceCompanyCardFeed at CompanyCards.ts:361-372. This is not the primary fix — the refetch guard is — but it keeps the action's successData/failureData symmetric and re-asserts the cardList if any unrelated writer touches the key during the suppression window.
Net change: one useRef + one conditional in WorkspaceCompanyCardsPage.tsx, one successData entry in CompanyCards.ts. No new Onyx fields, no finallyData, no cross-file coupling.
What alternative solutions did you explore? (Optional)
Changing OpenPolicyCompanyCardsFeed's response handler to MERGE rather than SET cardList would resolve this at the source and protect every future caller of the endpoint. It's cleaner but requires a backend change out of scope for this repo. The frontend guard ships today; the backend fix can follow independently.
A timer-based debounce on loadPolicyCompanyCardsFeed would also work but exposes the race as visible loading-flicker behavior and ties the fix to wall-clock assumptions about backend job latency.
📣 @15antonian! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
⚠️ @15antonian Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/antonioa62
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
@ProposalPolice this proposal identifies a different root cause than twilight2294's. twilight2294 attributes the clobber to importCSVCompanyCards missing a WORKSPACE_CARDS_LIST entry in successData and proposes adding that merge. My proposal identifies the openPolicyCompanyCardsFeed call — fired by WorkspaceCompanyCardsPage.tsx:84-86 after navigation back — as the actual clobber (its response SETs WORKSPACE_CARDS_LIST with the backend's still-empty state because the CSV import is processed asynchronously), and proposes guarding that refetch using the existing isFeedAdded transition. The successData merge I also mention is a secondary safety net, not the primary fix. Without the refetch guard, twilight2294's fix alone is a race.
Proposal
What is the root cause of that problem?
The bug is not a bad useCardsList key and it is not “missing confirmation” of optimistic data. The bug is a post-import read that overwrites already-correct optimistic state.
importCSVCompanyCardsimmediately writes the imported feed selection and optimisticWORKSPACE_CARDS_LIST.cardListentries into Onyx.CompanyCardsImportedPagethen returns straight to the Company Cards page.WorkspaceCompanyCardsPagealways callsopenPolicyCompanyCardsFeed()once loading settles.applyHTTPSOnyxUpdatesapplies HTTPSresponse.onyxDatabefore any requestsuccessData.
That means the imported cards are already present locally, but the first OPEN_POLICY_COMPANY_CARDS_FEED response can still come back with pre-import server state while backend CSV processing is catching up. That stale read replaces the optimistic WORKSPACE_CARDS_LIST, so the table goes empty again. The recording matches this exactly: after import the layout exists but the table is empty, and the cards only appear after later refresh/navigation once the backend has caught up.
What changes do you think we should make in order to solve the problem?
We should suppress exactly one feed reload: the first Company Cards feed read that happens immediately after a successful CSV import return. The cleanest way to do that is to reuse the existing ADD_NEW_COMPANY_CARD flow state instead of inventing a new flag.
- In
WorkspaceCompanyCardsPage.tsx, readONYXKEYS.ADD_NEW_COMPANY_CARD. - Treat the page as “returning from CSV import” only when all of these are true:
addNewCard.data.selectedBank === CONST.COMPANY_CARDS.BANKS.FILE_IMPORTaddNewCard.data.layoutType === bankNamecompanyCardEntries.length > 0
- Store that condition in a ref before the feed-load effect runs.
- In
loadPolicyCompanyCardsFeed(), if that ref is set, consume it once, callclearAddNewCardFlow(), and return without callingopenPolicyCompanyCardsFeed(). - Leave every later reload path unchanged: manual reload, reconnect, later navigation back, and ordinary non-import mounts should still call
openPolicyCompanyCardsFeed().
Tests that should be added:
- A Company Cards page test that seeds
ADD_NEW_COMPANY_CARDwith a file-import layout, seeds optimisticWORKSPACE_CARDS_LISTrows, and verifies the initial mount does not callopenPolicyCompanyCardsFeed(). - A companion test that verifies once the add-card flow state is cleared, the next reload path does call
openPolicyCompanyCardsFeed(). - A regression test that verifies normal non-import Company Cards mounts still fetch the feed immediately.
Demo
https://github.com/user-attachments/assets/faa20488-b98c-4e6f-8fc2-fa27a5b349a3
What alternative solutions did you explore? (Optional)
- Adding
WORKSPACE_CARDS_LISTtoimportCSVCompanyCards.successDatais incomplete. The bad overwrite happens later, whenopenPolicyCompanyCardsFeed()returns stale HTTPSonyxData, so a success-data merge on the write request does not eliminate the race. - The
selectedFeeddefault-value proposal does not match the actual behavior. The cards eventually appear after later refreshes, which points to a timing overwrite, not a permanently wrong Onyx key. - The later race-based proposals are directionally right, but a generic
isFeedAddedtransition or a brand-new “recent import” marker is broader than necessary. Reusing the existingADD_NEW_COMPANY_CARDfile-import state gives the same one-shot protection with a smaller, more targeted change and without adding a new Onyx field.
⚠️ @nabi-ebrahimi Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.