App icon indicating copy to clipboard operation
App copied to clipboard

[$175] Web - Company Cards - page loading infinitely with 'simulate failing network request'

Open lanitochka17 opened this issue 3 weeks ago • 21 comments

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: undefined Reproducible in staging?: Yes Reproducible in production?: undefined If this was caught during regression testing, add the test name, ID and link from BrowserStack: undefined Email or phone of affected tester (no customers): undefined Issue reported by: Applause Internal Team Bug source: undefined Device used: undefined App Component: undefined

Action Performed:

  1. Create a new workspace with 'simulate failing network requests' enabled in dev settings
  2. Navigate to Company Cards page for that workspace

Expected Result:

the error BlockingView is displayed

Actual Result:

page loading infinitely instead of error shown

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/5ebb1762-a460-4aaf-8308-49021beaf54f

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @cretadn22

lanitochka17 avatar Nov 09 '26 16:11 lanitochka17

Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (External)

melvin-bot[bot] avatar Nov 09 '26 16:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022119825058383936601

melvin-bot[bot] avatar Nov 09 '26 16:11 melvin-bot[bot]

🤖 Web test steps verification results: ⚠️ partial

Verification was blocked during setup on dev NewDot web. The reported behavior could not be confirmed or disproved. Global Search state where setup was blocked

Step Status
Enable simulated failing network requests and create a workspaceSetup was blocked: Global Search input attempts were rejected as covered by a dialog. No workspace was created.
Global Search state where setup was blocked
❌
Determine whether Company Cards displays an error BlockingView or persistent loadingNot tested because the required workspace fixture could not be established.
❌

Proposal

Confidence: Medium — the code explains the reported behavior, but runtime reproduction remains unverified.

What is the root cause of that problem?

Company Cards conflates an unresolved workspace account ID with an indefinitely pending request. Following simulated workspace-creation failure, the optimistic workspace remains without policyAccountID. The screen keeps showing loading, while its fallback error requires that same account-resolution wait to have finished.

Code evidence and alternative explanation checked
  1. The optimistic workspace does not include policyAccountID, and creation failure preserves that workspace: Policy.ts:2973–3073, failure handling:3266–3295.
  2. The missing account ID makes isPolicyLoaded=false: WorkspaceCompanyCardsPage.tsx:93–122.
  3. The cards action intentionally omits loading/error updates for fallback account ID 0. For valid account IDs, failure already clears isLoading, ruling out a generally missing reset: CompanyCards.ts:1095–1157.
  4. The table requires isPolicyLoaded to generate its missing-account error, while !isPolicyLoaded forces loading. BlockingView additionally requires loading to stop: table:145–185, rendering:539–576.

The simulator discards responses after server processing; this does not prove workspace creation failed server-side: HttpUtils.ts:120–150.

What changes do you think we should make in order to solve the problem?

Track the Company Cards page request’s pending/success/failure state by policy ID, independently of account-ID availability.

Pass terminal workspace-page errors explicitly to the table and let them display BlockingView instead of the initial loader. Preserve loading while creation genuinely remains pending; do not simply treat every missing account ID as an error.

Retry should clear the error and restart loading. Recovery after a lost creation response also needs verification: repeating the cards request alone is not proven to refresh the missing account ID.

Suggested regression coverage

Extend the existing page tests and table tests to verify:

  • Unresolved account ID plus terminal failure shows BlockingView.
  • Genuine pending creation retains the spinner without flashing an error.
  • Terminal page failure is not hidden by other initial-loading guards.
  • Retry failure remains actionable; successful account resolution restores normal rendering.

No source changes or automated tests were performed.

What alternative solutions did you explore? (Optional)

Simply setting isPolicyLoaded=true on failure is insufficient: other loading guards can still suppress BlockingView. Explicit terminal-error handling avoids misrepresenting the workspace as loaded.

Possibly related: Company Card — Infinite loading after going online also involves opening Company Cards around workspace creation/connectivity changes. A shared root cause is not established.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/106395) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 09 '26 16:11 MelvinBot

Proposal

What is the root cause of that problem?

In src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx:

// A freshly created workspace has no account ID until the back end returns one, so we can't treat the policy as loaded yet.
// Offline that response can never arrive, so we consider the policy loaded to avoid showing a spinner that would never resolve.
const isPolicyLoaded = !!policy && (policy.policyAccountID !== undefined || isOffline);
  1. When workspace creation fails (e.g. simulated network failure), the policy creation request fails and error state is set on policy.errors. Because creation failed, a backend response assigning policyAccountID will never arrive.
  2. Because the user is technically online (isOffline === false), isPolicyLoaded evaluates to false indefinitely.
  3. In src/components/Tables/WorkspaceCompanyCardsTable/index.tsx:
    • shouldShowWorkspaceFeedsLoadError requires isPolicyLoaded === true to locally synthesize CONST.COMPANY_CARDS.WORKSPACE_FEEDS_LOAD_ERROR (since Onyx discards writes to collection keys with member ID 0). Because isPolicyLoaded is false, the error is never synthesized.
    • isLoadingFeed evaluates !isPolicyLoaded as true, causing isLoading to remain true forever.
    • Consequently, <Table.LoadingState /> is rendered indefinitely, and the error BlockingView (which requires !isLoading) can never be rendered.

What changes do you think we should make in order to solve the problem?

  1. In src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx: Update isPolicyLoaded to also consider the policy loaded if creation has failed and policy.errors is populated (matching the pattern used across workspace pages via !isEmptyObject(policy.errors)):
const isPolicyLoaded = !!policy && (policy.policyAccountID !== undefined || isOffline || !isEmptyObject(policy.errors));
  1. In src/components/Tables/WorkspaceCompanyCardsTable/index.tsx: Guard isLoadingFeed so that if hasFeedErrors is true, feed loading state does not suppress the error view:
const isLoadingFeed = !hasCards && !hasFeedErrors && ((!feedName && isInitiallyLoadingFeeds) || !isPolicyLoaded || isLoadingOnyxFeed || isSelectedFeedLoading);

This guarantees that:

  • When workspace creation fails, isPolicyLoaded resolves to true.
  • shouldShowWorkspaceFeedsLoadError synthesizes the error correctly for workspace account ID 0.
  • isLoading stops immediately and the error BlockingView with the "Try Again" button is displayed as expected.

What alternative solutions did you explore? (Optional)

We could remove the optimistic policy on creation failure. However, Expensify's architecture intentionally preserves the optimistic policy with RBR error state in Onyx so the user can inspect errors and retry. Updating isPolicyLoaded to recognize !isEmptyObject(policy.errors) respects this architecture and aligns WorkspaceCompanyCardsPage with the rest of the workspace settings screens.

Tests

  1. Enable 'Simulate failing network requests' in Settings > Developer settings.
  2. Create a new workspace.
  3. Navigate to the Company Cards page for that workspace.
  4. Verify that the error BlockingView ("Workspace feeds could not be loaded" / "Try Again") is displayed instead of an infinite loading spinner.
  5. Turn off 'Simulate failing network requests' and click 'Try Again'.
  6. Verify normal loading and feed resolution behavior.

  • Contributor: @kevinjosh10
  • Expensify Account Email: [email protected]
  • Upwork Profile: https://www.upwork.com/freelancers/~0131dae36abcf59374

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 09 '26 16:11 kevinjosh10

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0179cdc82689f205c7

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Web, when navigating to the Workspace Company Cards page with simulated failing network requests enabled, the page remains stuck in an infinite loading skeleton/spinner with no error state or recovery mechanism.

What is the root cause of that problem?

In src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx, the loading indicator condition depends on isLoading from card feed queries. When the network request fails, the API failure handler fails to clear the pending loading flag in Onyx or local state, leaving isLoading true indefinitely while no retry CTA or offline indicator is rendered.

What changes do you think we should make in order to solve the problem?

  1. In src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx, verify isOffline and policy.errors alongside isLoading.
  2. When a network error occurs, ensure isLoading is set to false and render FullScreenLoadingIndicator fallback or BlockingView with an explicit retry button.
  3. Ensure the API failure callback for OpenPolicyCompanyCardsPage resets the loading state in Onyx.

What alternative solutions did you explore? (Optional)

  • Global timeout force-refresh: Rejected because individual pages should gracefully display localized error boundaries and offline indicators per Expensify design standards.

What automated tests can you add to prevent this from re-occurring?

In tests/unit/WorkspaceCompanyCardsPageTest.ts:

  • Add a test verifying that when company card feeds fail to load due to a network error, the page stops showing the loading spinner and renders an error/retry state.

TassioSales avatar Nov 09 '26 18:11 TassioSales

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 09 '26 18:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Web, when navigating to the Workspace Company Cards page for a newly created workspace while "Simulate failing network requests" is enabled, the page is stuck in an infinite loading spinner instead of displaying the error BlockingView with a "Try Again" recovery button.

What is the root cause of that problem?

There is a dual deadlock between isPolicyLoaded in WorkspaceCompanyCardsPage.tsx and the error/loading state evaluation in WorkspaceCompanyCardsTable/index.tsx:

  1. isPolicyLoaded remains false forever on failed creation: In src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx:93:

    const isPolicyLoaded = !!policy && (policy.policyAccountID !== undefined || isOffline);
    

    When workspace creation fails under simulated network failure:

    • The device is still online (isOffline === false).
    • The optimistic policy is preserved in Onyx with error state (policy.errors / Red Brick Road), but policy.policyAccountID remains undefined because the backend creation request failed.
    • Because policyAccountID is undefined and isOffline is false, isPolicyLoaded evaluates to false indefinitely.
  2. Error synthesis is blocked by isPolicyLoaded: In src/components/Tables/WorkspaceCompanyCardsTable/index.tsx:146:

    const shouldShowWorkspaceFeedsLoadError = domainOrWorkspaceAccountID === CONST.DEFAULT_NUMBER_ID && isPolicyLoaded && !isOffline;
    

    Because isPolicyLoaded is false, shouldShowWorkspaceFeedsLoadError evaluates to false. Therefore, the table never synthesizes CONST.COMPANY_CARDS.WORKSPACE_FEEDS_LOAD_ERROR, leaving hasFeedErrors === false.

  3. isLoadingFeed is stuck true due to !isPolicyLoaded: In src/components/Tables/WorkspaceCompanyCardsTable/index.tsx:184-185:

    const isLoadingFeed = !hasCards && ((!feedName && isInitiallyLoadingFeeds) || !isPolicyLoaded || isLoadingOnyxFeed || isSelectedFeedLoading);
    const isLoading = isLoadingPage || isLoadingFeed || isLoadingOnyxCardList;
    

    Because !isPolicyLoaded is true, isLoadingFeed (and consequently isLoading) evaluates to true indefinitely.

  4. BlockingView error is suppressed by isLoading: In src/components/Tables/WorkspaceCompanyCardsTable/index.tsx:556: The error view requires {!!feedErrorKey && !isLoading && (...). Because isLoading is stuck at true, the error BlockingView is never rendered, and the user is trapped watching the infinite loading spinner <Table.LoadingState />.


What changes do you think we should make in order to solve the problem?

  1. Update isPolicyLoaded in WorkspaceCompanyCardsPage.tsx: Recognize that if a policy has failed creation and holds errors (!isEmptyObject(policy.errors)), the policy is loaded as far as the client is concerned (no server account ID will arrive without a retry):

    // In src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx:
    import {isEmptyObject} from '@src/types/utils/EmptyObject';
    
    // A freshly created workspace has no account ID until the back end returns one, so we can't treat the policy as loaded yet.
    // Offline or on creation failure, that response can never arrive, so we consider the policy loaded to avoid showing a spinner that would never resolve.
    const isPolicyLoaded = !!policy && (policy.policyAccountID !== undefined || isOffline || !isEmptyObject(policy.errors));
    
  2. Guard isLoadingFeed with !hasFeedErrors in WorkspaceCompanyCardsTable/index.tsx: Ensure feed loading state does not override an active feed error:

    // In src/components/Tables/WorkspaceCompanyCardsTable/index.tsx:
    const isLoadingFeed = !hasCards && !hasFeedErrors && ((!feedName && isInitiallyLoadingFeeds) || !isPolicyLoaded || isLoadingOnyxFeed || isSelectedFeedLoading);
    

With these two surgical changes:

  • When workspace creation fails, isPolicyLoaded evaluates to true.
  • shouldShowWorkspaceFeedsLoadError cleanly synthesizes CONST.COMPANY_CARDS.WORKSPACE_FEEDS_LOAD_ERROR for workspace account ID 0.
  • isLoadingFeed stops loading (isLoading === false).
  • The error BlockingView renders with the Try Again CTA button linked to onReloadPage.
  • When network is restored and the user taps Try Again, openPolicyCompanyCardsPage is re-triggered cleanly.

What alternative solutions did you explore? (Optional)

  • Discarding the optimistic policy in Onyx on creation failure: Rejected because Expensify intentionally preserves failed optimistic policies so users can see the Red Brick Road error and retry.
  • Overriding isLoading globally when policy.errors is non-empty: Rejected as too broad, which could inadvertently suppress valid loading states on other sub-components. Restricting the change to isPolicyLoaded and guarding isLoadingFeed with !hasFeedErrors is minimal, surgical, and follows existing workspace patterns.

What specific scenarios should we cover in automated tests?

In tests/ui/WorkspaceCompanyCardsTableTest.tsx:

  1. Render error BlockingView on failed workspace creation:
    • Render WorkspaceCompanyCardsTable with domainOrWorkspaceAccountID = CONST.DEFAULT_NUMBER_ID, isPolicyLoaded = true, and isOffline = false.
    • Verify that <Table.LoadingState /> is not rendered.
    • Verify that BlockingView is rendered with workspaceFeedsCouldNotBeLoadedTitle and the "Try Again" button.
  2. In tests/ui/WorkspaceCompanyCardsPageSelectionModeTest.tsx:
    • Verify isPolicyLoaded resolves to true when policy.policyAccountID is undefined but policy.errors is populated.

Contributor details

Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/~013bdd0475abb70c10

gorky117-cell avatar Nov 10 '26 11:11 gorky117-cell

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 10 '26 11:11 melvin-bot[bot]

Reproduction notes — staging v9.5.35-1, Chrome on macOS, November 10.

I followed the issue steps with Simulate failing network requests enabled and Force offline disabled. One fresh workspace reached the expected “Couldn’t load card feeds” error with Try again. After confirming the failure setting in the same tab, a second fresh workspace stayed on the Company Cards spinner for several minutes, with no error or retry button.

A masked Onyx export taken while the second page was stuck showed:

Workspace result policyAccountID policy.errors policy.errorFields
Error view with retry Present Absent Absent
Persistent spinner Absent Absent Absent

This supports the account-ID/loading deadlock described in MelvinBot’s proposal, and gives a case an errors-only policy guard would miss.

Disabling simulated failures did not clear the already-mounted spinner at the next observation. Reloading with normal requests restored the normal BYOC/Add cards page. This does not establish that creation failed server-side: the simulator discards the response after server processing.

These are reproduction observations only; I have not applied a fix or run automated tests. The full state export contains unrelated account data and is not attached.

Shivam1817 avatar Nov 10 '26 12:11 Shivam1817

Proposal

Please re-state the problem that we are trying to solve in this issue.

When creating a new workspace while Simulate failing network requests is enabled and navigating to the Company Cards page for that workspace, the page gets stuck in an infinite loading spinner instead of displaying the error BlockingView with a Try again button.

What is the root cause of that problem?

Two conditions combine to lock the Company Cards table in a permanent loading state when workspace creation fails without resolving policy.policyAccountID:

  1. isPolicyLoaded stays false when policy.policyAccountID is unresolved, and createWorkspace does not set policy.errors:
    • In WorkspaceCompanyCardsPage.tsx, isPolicyLoaded only becomes true when policy.policyAccountID !== undefined || isOffline.
    • In Policy.ts, createWorkspace failureData merges {employeeList: null, owner, ownerAccountID} into policy_${policyID} and never sets policy.errors. When workspace creation fails with a simulated network error, both policy.policyAccountID and policy.errors remain undefined while isOffline is false, so isPolicyLoaded stays false.
  2. openPolicyCompanyCardsPage skips all loading/error writes when domainOrWorkspaceAccountID === 0 (CONST.DEFAULT_NUMBER_ID):
    • In CompanyCards.ts, onyxLoadingStateUpdates is domainOrWorkspaceAccountID !== CONST.DEFAULT_NUMBER_ID. When policyAccountID is undefined, domainOrWorkspaceAccountID defaults to 0, so optimisticData, successData, and failureData are all empty arrays ([]).
    • When OPEN_POLICY_COMPANY_CARDS_PAGE fails immediately due to simulated network failure, no failure state is recorded anywhere in Onyx.
    • In WorkspaceCompanyCardsTable/index.tsx, shouldShowWorkspaceFeedsLoadError requires isPolicyLoaded, and isLoadingFeed includes !isPolicyLoaded, so <Table.LoadingState /> renders indefinitely and the error BlockingView ({!!feedErrorKey && !isLoading}) can never appear.

What changes do you think we should make in order to solve the problem?

Follow the existing Expensify Card pattern (openPolicyExpensifyCardsPage with RAM_ONLY_EXPENSIFY_CARD_LOADING_STATE keyed by policyID) using ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE:

  1. Extend CompanyCardsLoadingState (src/types/onyx/CompanyCardsLoadingState.ts) with optional policy-scoped fields isPageLoading?: boolean and hasPageLoadError?: boolean.
  2. Track page load & failure state unconditionally by policyID in openPolicyCompanyCardsPage (src/libs/actions/CompanyCards.ts):
    • optimisticData: set {isPageLoading: true, hasPageLoadError: false} on ${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID} (regardless of whether domainOrWorkspaceAccountID === 0).
    • successData: set {isPageLoading: false, hasPageLoadError: false, hasOnceLoadedPage: true}.
    • failureData: set {isPageLoading: false, hasPageLoadError: true} while preserving existing domain-keyed SHARED_NVP_PRIVATE_DOMAIN_MEMBER writes when domainOrWorkspaceAccountID !== CONST.DEFAULT_NUMBER_ID.
  3. Update WorkspaceCompanyCardsPage.tsx and WorkspaceCompanyCardsTable/index.tsx:
    • Read ${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID}.
    • Allow isPolicyLoaded to resolve when policyCompanyCardsLoadingState?.hasOnceLoadedPage is true so a successful retry unblocks the table even if the earlier CreateWorkspace response was discarded.
    • In WorkspaceCompanyCardsTable, derive hasPageLoadError = !!policyCardsLoadingState?.hasPageLoadError && !policyCardsLoadingState?.isPageLoading. When !isOffline && hasPageLoadError, surface WORKSPACE_FEEDS_LOAD_ERROR and bypass the !isPolicyLoaded hold in isLoadingFeed so BlockingView with Try again renders cleanly. While CreateWorkspace is genuinely pending (!hasPageLoadError) or retrying (isPageLoading === true), keep showing <Table.LoadingState />.
  4. Add regression unit tests in tests/ui/WorkspaceCompanyCardsTableTest.tsx covering failed page fetches with isPolicyLoaded: false / domainOrWorkspaceAccountID: 0 and returning to the loading indicator on retry.

Verified branch & compare: https://github.com/Expensify/App/compare/main...bhomvratrai-glitch:App:fix/106395-company-cards-infinite-loading

What alternative solutions did you explore? (Optional)

  • Checking !isEmptyObject(policy.errors) in isPolicyLoaded: Rejected because Policy.createWorkspace's failureData does not set policy.errors in Onyx (confirmed in Policy.ts:3266-3275 and in the Onyx dump above where policyAccountID and policy.errors are both absent), so an errors-only guard still leaves the page stuck in an infinite spinner.
  • Decoupling shouldShowWorkspaceFeedsLoadError from isPolicyLoaded (domainOrWorkspaceAccountID === CONST.DEFAULT_NUMBER_ID && !isOffline) or marking isPolicyLoaded = true unconditionally: Rejected because it prematurely flashes the error BlockingView while a new workspace's CreateWorkspace request is still genuinely in flight, breaking the existing regression test in WorkspaceCompanyCardsTableTest.tsx:292-299 ("keeps the loading indicator up instead of flashing the feeds load error while the policy account ID is unresolved").

bhomvratrai-glitch avatar Nov 10 '26 12:11 bhomvratrai-glitch

Thanks @Shivam1817 for the reproduction data! This confirms the exact deadlock between isPolicyLoaded and the synthesized error check in WorkspaceCompanyCardsTable:

  1. Why domainOrWorkspaceAccountID === 0 skips Onyx error writes:
    In src/libs/actions/CompanyCards.ts (line 1096):

    const onyxLoadingStateUpdates = domainOrWorkspaceAccountID !== CONST.DEFAULT_NUMBER_ID;
    

    When policyAccountID is missing, domainOrWorkspaceAccountID is 0, so CompanyCards.ts intentionally avoids writing failureData to Onyx because collection keys ending in 0 are ignored.

  2. The deadlock in WorkspaceCompanyCardsTable:
    To compensate for this, line 146 attempts to synthesize the error:

    const shouldShowWorkspaceFeedsLoadError = domainOrWorkspaceAccountID === CONST.DEFAULT_NUMBER_ID && isPolicyLoaded && !isOffline;
    

    However, because isPolicyLoaded in WorkspaceCompanyCardsPage.tsx requires policy.policyAccountID !== undefined || isOffline, when online without an account ID, isPolicyLoaded is false. Thus, shouldShowWorkspaceFeedsLoadError is never set, while !isPolicyLoaded in isLoadingFeed (line 184) keeps the page stuck in isLoading indefinitely.

  3. Surgical Solution:
    In src/components/Tables/WorkspaceCompanyCardsTable/index.tsx:

    • Decouple shouldShowWorkspaceFeedsLoadError from isPolicyLoaded:
      const shouldShowWorkspaceFeedsLoadError = domainOrWorkspaceAccountID === CONST.DEFAULT_NUMBER_ID && !isOffline;
      
    • Guard isLoadingFeed with !hasFeedErrors:
      const isLoadingFeed = !hasCards && !hasFeedErrors && ((!feedName && isInitiallyLoadingFeeds) || !isPolicyLoaded || isLoadingOnyxFeed || isSelectedFeedLoading);
      

This guarantees that whenever domainOrWorkspaceAccountID === 0 online, the synthesized error is recognized, isLoadingFeed yields to the error state, and the BlockingView with "Try Again" is displayed immediately, regardless of whether policy.errors is present or absent in Onyx.

gorky117-cell avatar Nov 10 '26 12:11 gorky117-cell

@aimane-chnaif Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Nov 12 '26 21:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When creating a new workspace while Simulate failing network requests is enabled in developer settings and navigating to the Company Cards page for that workspace, the page gets stuck in an infinite loading spinner instead of displaying the error BlockingView with a Try again button.

What is the root cause of that problem?

The infinite spinner is caused by a loading/error state deadlock when policy.policyAccountID has not resolved yet (domainOrWorkspaceAccountID === 0):

  1. isPolicyLoaded stays false when CreateWorkspace fails (WorkspaceCompanyCardsPage.tsx:104):

    • In src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx:104:
      const isPolicyLoaded = !!policy && (policy.policyAccountID !== undefined || isOffline);
      
    • When CreateWorkspace fails due to simulated network failure, src/libs/actions/Policy/Policy.ts:3266-3275 (failureData) merges {employeeList: null, owner, ownerAccountID} into policy_${policyID} and never sets policy.errors or policy.policyAccountID. Because the client is still online (isOffline === false), isPolicyLoaded remains false indefinitely.
  2. openPolicyCompanyCardsPage drops all loading/success/failure Onyx updates when domainOrWorkspaceAccountID === 0 (CompanyCards.ts:1097-1146):

    • Because Onyx skips collection writes to member ID '0' (CONST.SKIPPABLE_COLLECTION_MEMBER_IDS), openPolicyCompanyCardsPage gates optimisticData, successData, and failureData behind const onyxLoadingStateUpdates = domainOrWorkspaceAccountID !== CONST.DEFAULT_NUMBER_ID;.
    • When policy.policyAccountID is undefined, domainOrWorkspaceAccountID falls back to 0, so openPolicyCompanyCardsPage sends OPEN_POLICY_COMPANY_CARDS_PAGE with optimisticData: [], successData: [], and failureData: []. When that request fails, no error or settled flag is written anywhere in Onyx.
  3. Three separate loading guards in WorkspaceCompanyCardsTable/index.tsx keep isLoading === true:

    • Guard A (shouldShowWorkspaceFeedsLoadError, line 147): domainOrWorkspaceAccountID === CONST.DEFAULT_NUMBER_ID && isPolicyLoaded && !isOffline evaluates to false because isPolicyLoaded is false, so hasFeedErrors remains false.
    • Guard B (isLoadingFeed, line 185): includes !isPolicyLoaded, forcing isLoadingFeed = true.
    • Guard C (isLoadingPage, lines 141, 176-177, 184): hasOnceLoadedPage is read only from ${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${domainOrWorkspaceAccountID} (companyCardsLoadingState_0, which Onyx skips!). Even if the user disables simulated failures and taps Try again so OPEN_POLICY_COMPANY_CARDS_PAGE succeeds for a workspace with 0 card feeds (allCardFeeds empty -> isPageFetchPending === true) while domainOrWorkspaceAccountID is still 0 (because the earlier CreateWorkspace response was discarded by the simulator), hasOnceLoadedPage on companyCardsLoadingState_0 stays false, keeping areWorkspaceCardFeedsLoading = true and isLoadingPage = true forever on retry!

What changes do we think we should make in order to solve the problem?

Mirror the exact policy-keyed pattern already established in openPolicyExpensifyCardsPage (src/libs/actions/Policy/Policy.ts:4474-4509 + src/types/onyx/ExpensifyCardLoadingState.ts + WorkspaceExpensifyCardPage.tsx:43-65), using ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE keyed by policyID (${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID} — a string policy ID never collides with numeric domainOrWorkspaceAccountID keys and is never skipped by SKIPPABLE_COLLECTION_MEMBER_IDS):

  1. Extend src/types/onyx/CompanyCardsLoadingState.ts: Add optional policy-scoped fields isLoadingPage?: boolean and hasLoadingError?: boolean alongside hasOnceLoadedPage?: boolean:

    /** Whether the workspace company cards page request is currently in flight (keyed by policyID) */
    isLoadingPage?: boolean;
    
    /** Whether the latest workspace company cards page request failed (keyed by policyID) */
    hasLoadingError?: boolean;
    
  2. Record page-level loading, success, and failure unconditionally under ${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID} in src/libs/actions/CompanyCards.ts (openPolicyCompanyCardsPage):

    • optimisticData: always merge {isLoadingPage: true, hasLoadingError: false} into ${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID} (and keep the SHARED_NVP_PRIVATE_DOMAIN_MEMBER write when onyxLoadingStateUpdates is true).
    • successData: always merge {isLoadingPage: false, hasLoadingError: false, hasOnceLoadedPage: true} into ${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID} (plus existing domain-keyed writes when onyxLoadingStateUpdates is true).
    • failureData: always merge {isLoadingPage: false, hasLoadingError: true} into ${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID} (plus existing domain-keyed error writes when onyxLoadingStateUpdates is true).
  3. Unblock both initial failure AND retry success in WorkspaceCompanyCardsPage.tsx and WorkspaceCompanyCardsTable/index.tsx:

    • In src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx: Read const [policyCompanyCardsLoadingState] = useOnyx(${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID}); and update isPolicyLoaded:
      const isPolicyLoaded = !!policy && (policy.policyAccountID !== undefined || isOffline || !!policyCompanyCardsLoadingState?.hasOnceLoadedPage);
      
    • In src/components/Tables/WorkspaceCompanyCardsTable/index.tsx: Read const [policyCompanyCardsLoadingState] = useOnyx(${ONYXKEYS.COLLECTION.RAM_ONLY_COMPANY_CARDS_LOADING_STATE}${policyID}); and derive:
      • Combine hasOnceLoadedPage across both keys (critical for empty-workspace retry when domainOrWorkspaceAccountID === 0):
        const hasOnceLoadedPage = !!companyCardsLoadingState?.hasOnceLoadedPage || !!policyCompanyCardsLoadingState?.hasOnceLoadedPage;
        const isPolicyPageLoading = !!policyCompanyCardsLoadingState?.isLoadingPage;
        const hasPolicyPageLoadError = !!policyCompanyCardsLoadingState?.hasLoadingError && !isPolicyPageLoading;
        
      • Synthesize WORKSPACE_FEEDS_LOAD_ERROR when hasPolicyPageLoadError is true (and clear it while retrying):
        const shouldShowWorkspaceFeedsLoadError =
            !isOffline &&
            !isPolicyPageLoading &&
            ((domainOrWorkspaceAccountID === CONST.DEFAULT_NUMBER_ID && (isPolicyLoaded || hasPolicyPageLoadError)) ||
                (hasPolicyPageLoadError && !workspaceCardFeedsStatus?.[domainOrWorkspaceAccountID]?.errors));
        
      • Include isPolicyPageLoading in areWorkspaceCardFeedsLoading and release !isPolicyLoaded when hasFeedErrors is active:
        const areWorkspaceCardFeedsLoading =
            (!!workspaceCardFeedsStatus?.[domainOrWorkspaceAccountID]?.isLoading || isPolicyPageLoading || isPageFetchAwaited) && !hasOnceLoadedPage;
        const isLoadingFeed = !hasCards && !hasFeedErrors && ((!feedName && isInitiallyLoadingFeeds) || !isPolicyLoaded || isLoadingOnyxFeed || isSelectedFeedLoading);
        
    • Add unit/UI tests in tests/ui/WorkspaceCompanyCardsTableTest.tsx covering: (a) unresolved policyAccountID while CreateWorkspace + page fetch are still in flight keeps <Table.LoadingState /> without flashing an error, (b) failed page fetch with domainOrWorkspaceAccountID === 0 renders BlockingView + Try again, (c) tapping Try again returns to <Table.LoadingState /> while isLoadingPage: true, and (d) successful retry on a workspace with no feeds (domainOrWorkspaceAccountID === 0, hasOnceLoadedPage: true on policy key) renders WorkspaceCompanyCardPageEmptyState instead of staying stuck on areWorkspaceCardFeedsLoading.

What alternative solutions did you explore? (Optional)

  • Checking !isEmptyObject(policy.errors) in isPolicyLoaded: Does not work because Policy.createWorkspace failureData (Policy.ts:3266-3275) never populates policy.errors in Onyx, leaving isPolicyLoaded stuck at false.
  • Removing isPolicyLoaded from shouldShowWorkspaceFeedsLoadError (domainOrWorkspaceAccountID === CONST.DEFAULT_NUMBER_ID && !isOffline): Breaks normal workspace creation by immediately flashing the WORKSPACE_FEEDS_LOAD_ERROR BlockingView while CreateWorkspace and OpenPolicyCompanyCardsPage are legitimately in flight (failing the existing regression test in WorkspaceCompanyCardsTableTest.tsx:292-299).
  • Reading hasOnceLoadedPage only from companyCardsLoadingState_${domainOrWorkspaceAccountID} inside WorkspaceCompanyCardsTable: Leaves hasOnceLoadedPage === false when a retry succeeds while domainOrWorkspaceAccountID is still 0 (because the initial CreateWorkspace HTTP response was discarded by simulated failure), keeping isPageFetchAwaited && !hasOnceLoadedPage stuck in an infinite loading state on empty workspaces. Combining !!companyCardsLoadingState?.hasOnceLoadedPage || !!policyCompanyCardsLoadingState?.hasOnceLoadedPage closes that retry deadlock completely.

cocvn157 avatar Nov 13 '26 15:11 cocvn157

@aimane-chnaif Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

@aimane-chnaif 10 days overdue. I'm getting more depressed than Marvin.

Claude posting on behalf of Matt:

@cretadn22 you're now the C+ on this issue. The previous C+ is no longer in the Contributor program. Next step: review the proposals.

mallenexpensify avatar Nov 23 '26 22:11 mallenexpensify

@MelvinBot I was able to reproduce this bug on my end. Could you retry the reproduction steps and verify your original proposal?

cretadn22 avatar Nov 25 '26 05:11 cretadn22

🤖 Web test steps verification results: ⚠️ partial

Created a new workspace on dev NewDot web with simulated failures enabled and Force offline disabled. Automation could not navigate to Company Cards, so I could not confirm the reported behavior or verify my original proposal. Workspace Overview where Company Cards navigation was blocked by automation

Step Status
Create a workspace with simulated failures enabledEnabled simulated failures and confirmed the new workspace through UI read-back. Screenshot shows baseline settings before enabling failures.
Baseline developer settings before simulated failures were enabled
✅
Navigate to Company CardsAutomation blocker: Company Cards was visible in the sidebar but absent from accessibility read-back. No supported navigation tool was available. This is not a confirmed product failure.
Workspace Overview where Company Cards navigation was blocked by automation
❌
Verify persistent loading versus error BlockingViewNot reached; neither outcome was verified.
❌
Disable failures and verify recoveryDisabled simulated failures during cleanup. Company Cards recovery and Try again remain untested.
❌
Verify the original proposalThe unresolved-account-ID hypothesis remains unconfirmed by this runtime attempt. My original proposal is still provisional—not a verified fix. No source changes were made.
❌

view run · view recording

MelvinBot avatar Nov 25 '26 05:11 MelvinBot

@MelvinBot Implement this

cretadn22 avatar Nov 28 '26 07:11 cretadn22

🤖 Web test steps verification results: ❌ fail

Implemented in draft PR: Show Company Cards load errors and support retry recovery. The latest web recheck was blocked by a blank page, so revised retry recovery remains unverified. Blank app page blocked verification of the revised recovery handling

Step Status
Create a workspace with simulated failures enabledCreated the workspace with simulated failures enabled and Force offline off.
✅
Verify actionable Company Cards failureDisplayed “Couldn't load card feeds” and “Try again” instead of endless loading.
✅
Retry while failures remain enabledReturned to the actionable error; the brief loading transition was not captured.
✅
Disable failures and retry recoveryThe first implementation remained in error. Recovery handling was subsequently revised.
Company Cards remained in an error state during the first recovery test
❌
Recheck revised failure and recovery behaviorBlocked by a blank app page; no product verdict was possible.
Blank app page blocked verification of the revised recovery handling
❌
Confirm simulated failures are off after recheckSettings were inaccessible. The first test disabled failures; the recheck changed no settings.
❌

Automated checks passed: 32 focused tests, lint, typecheck, spelling, explicit-file React Compiler checks, formatting hook, and Storybook smoke test. PR remains draft pending browser recovery verification.


view run · no recording available

MelvinBot avatar Nov 28 '26 08:11 MelvinBot