Skip to content

[Due for payment 2025-12-03] [$250] Expense - After clearing cache, starting per diem flow shows empty state page briefly #74272

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: V9.2.44-1
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://test-management.browserstack.com/projects/2219752/test-runs/TR-1795/folder/13176674/53829876/994331412
Email or phone of affected tester (no customers): Slottwo1 72old.approver@gmail.com
Issue reported by: Applause Internal Team
Device used: Redminote 10s android 13
App Component: Money Requests

Action Performed:

  1. Launch app
  2. Create a workpace and set it as default
  3. Create another workspace - enable per diem - upload per diem rates
    4.Go to troubleshoot and clear cache
  4. Go to inbox
  5. Tap Fab - create expense - per diem

Expected Result:

After clearing cache, starting per diem flow musn't show empty state page briefly.

Actual Result:

After clearing cache, starting per diem flow shows empty state page briefly.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021986272881400271924
  • Upwork Job ID: 1986272881400271924
  • Last Price Increase: 2025-11-20
Issue OwnerCurrent Issue Owner: @RachCHopkins

Activity

  1. added
    Daily
    Bug
    on Nov 5, 2025
  2. melvin-bot commented on Nov 5, 2025

    @melvin-bot

    Triggered auto assignment to @RachCHopkins (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. nyomanjyotisa commented on Nov 5, 2025

    @nyomanjyotisa
    Member

    Proposal

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

    Expense - After clearing cache, starting per diem flow shows empty state page briefly

    What is the root cause of that problem?

    When cache is cleared, customUnit?.rates becomes empty and shouldShowEmptyState becomes true.

    const isLoading = !isOffline && isLoadingOnyxValue(policyMetadata);
    const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && !isOffline;

    The component then fetches the per diem rates via fetchPerDiemRates in the useEffect, but there's no loading state tracking this fetch operation. The isLoading variable only tracks policyMetadata loading status, not the per diem rates fetch

    useEffect(() => {
    if (!isEmptyObject(customUnit?.rates) || isOffline) {
    return;
    }
    fetchPerDiemRates(policy?.id);
    // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
    }, [isOffline]);

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

    We can add a local state to track per diem rates fetching

        const [isLoadingPerDiemRates, setIsLoadingPerDiemRates] = useState(false);

    Then update the useEffect that fetches rates

        useEffect(() => {
            if (!isEmptyObject(customUnit?.rates) || isOffline) {
                setIsLoadingPerDiemRates(false);
                return;
            }
            setIsLoadingPerDiemRates(true);
            fetchPerDiemRates(policy?.id);
            // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
        }, [isOffline]);

    useEffect(() => {
    if (!isEmptyObject(customUnit?.rates) || isOffline) {
    return;
    }
    fetchPerDiemRates(policy?.id);
    // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
    }, [isOffline]);

    We also need to add another useEffect to reset loading state when rates are loaded

        useEffect(() => {
            if (customUnit?.rates !== undefined) {
                setIsLoadingPerDiemRates(false);
            }
        }, [customUnit?.rates]);

    Then update isLoading and shouldShowEmptyState to include the per diem fetch state

        const isLoading = (!isOffline && isLoadingOnyxValue(policyMetadata)) || isLoadingPerDiemRates;
        const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && !isOffline && !isLoadingPerDiemRates;

    const isLoading = !isOffline && isLoadingOnyxValue(policyMetadata);
    const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && !isOffline;

    What alternative solutions did you explore? (Optional)

    None

  4. paulnjs commented on Nov 5, 2025

    @paulnjs
    Contributor

    Proposal

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

    After clearing the cache, starting the per diem flow briefly displays an empty state page.

    What is the root cause of that problem?

    When the per diem data is loading via this call:

    fetchPerDiemRates(policy?.id);

    the shouldShowEmptyState variable is set to true:
    const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && !isOffline;

    As a result, the empty state is shown while the per diem data is still loading.

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

    We should update the isLoading calculation at:

    const isLoading = !isOffline && isLoadingOnyxValue(policyMetadata);

    to include the isLoadingPerdiem flag. The updated logic should look like:

    
    const isLoading = !isOffline && (isLoadingOnyxValue(policyMetadata) || policy?.customUnits?.isLoadingPerdiem);
    const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && !isOffline && !isLoading;
    

    The isLoadingPerdiem flag is set to true optimistically in fetchPerDiemRate, and reset to null in both successData and failureData:

    function fetchPerDiemRates(policyID: string | undefined) {

    What alternative solutions did you explore? (Optional)

  5. bernhardoj commented on Nov 5, 2025

    @bernhardoj
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-11-18 04:46:10 UTC.

    Proposal

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

    After clearing cache and restart, per diem destination page shows empty state briefly.

    What is the root cause of that problem?

    The empty state view will show if the per diem custom unit rates are empty.

    const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && !isOffline;

    After clearing cache and restart, the policy object doesn't have the customUnits field and only loaded here.

    useEffect(() => {
    if (!isEmptyObject(customUnit?.rates) || isOffline) {
    return;
    }
    fetchPerDiemRates(policy?.id);
    // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
    }, [isOffline]);

    The loading will only show if the policy onyx data is loading.

    const isLoading = !isOffline && isLoadingOnyxValue(policyMetadata);

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

    We can show the loading if the custom units is missing and prevent showing the empty state if it's loading.

    const isLoading = !isOffline && isLoadingOnyxValue(policyMetadata);
    const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && !isOffline;

    const isLoading = !isOffline && (!customUnit?.rates || isLoadingOnyxValue(policyMetadata));
    const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && !isOffline && !isLoading;

    After clear cache and restart, customUnit?.rates will be undefined, so the loading will show. After loaded, if the rates is empty, !customUnit?.rates will evaluate to false, so the loading won't show if the rates is empty.

  6. added
    External
    on Nov 6, 2025
  7. changed the title [-]Expense - After clearing cache, starting per diem flow shows empty state page briefly[/-] [+][$250] Expense - After clearing cache, starting per diem flow shows empty state page briefly[/+] on Nov 6, 2025
  8. melvin-bot commented on Nov 6, 2025

    @melvin-bot
  9. added
    Help Wanted
    on Nov 6, 2025
  10. melvin-bot commented on Nov 6, 2025

    @melvin-bot

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

  11. IjaazA commented on Nov 6, 2025

    @IjaazA
    Contributor

    Proposal

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

    After clearing cache and starting the per diem expense creation flow, an empty state page is briefly displayed before the per diem destination picker appears. The expected behavior is that the empty state should not appear at all when starting the per diem flow after clearing cache.

    What is the root cause of that problem?

    The issue occurs because when cache is cleared, the per diem rates are not yet loaded in Onyx when the IOURequestStepDestination component mounts. The component checks if customUnit?.rates is empty and immediately shows the empty state page, even though rates are being fetched asynchronously.

    The logic flow is:

    1. Component mounts with empty rates (cache was cleared)
    2. shouldShowEmptyState evaluates to true because isEmptyObject(customUnit?.rates) is true
    3. Empty state is rendered briefly
    4. useEffect then calls fetchPerDiemRates() to load the rates
    5. Once rates are loaded, the empty state disappears and the destination picker is shown

    The problem is that the component doesn't distinguish between:

    • Rates are loading (after cache clear) → should show loading indicator
    • Rates are truly empty (no rates configured) → should show empty state

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

    Add logic to track whether we've initiated a fetch for per diem rates, and show a loading state instead of empty state when rates are expected but not yet loaded.

    Pseudo Code:

    // Track if we've initiated a fetch to distinguish between "rates are loading" and "rates are truly empty"
    const hasInitiatedFetch = useRef(false);
    
    // If per diem is enabled but rates are empty, we might be loading them after cache clear
    // Show loading state instead of empty state to prevent brief empty state flash
    // Once we've fetched and confirmed rates are empty, show empty state
    const isPerDiemEnabled = policy?.arePerDiemRatesEnabled === true;
    
    // Show loading if: per diem is enabled, rates are empty, we're online, policy is loaded, 
    // and we haven't confirmed rates are empty yet
    const isRatesLoading = isPerDiemEnabled && 
        isEmptyObject(customUnit?.rates) && 
        !isOffline && 
        !isLoadingOnyxValue(policyMetadata) && 
        !hasInitiatedFetch.current;
    
    // Only show empty state if rates are empty AND we've already initiated fetch 
    // (meaning we've confirmed they're truly empty)
    const shouldShowEmptyState = isEmptyObject(customUnit?.rates) && 
        !isOffline && 
        hasInitiatedFetch.current;
    
    // In the useEffect that fetches rates:
    useEffect(() => {
        if (!isEmptyObject(customUnit?.rates) || isOffline) {
            return;
        }
        hasInitiatedFetch.current = true; // Mark that we've started fetching
        fetchPerDiemRates(policy?.id);
    }, [isOffline]);
    
    // Show loading indicator when either policy is loading or rates are loading
    {(isLoading || isRatesLoading) && (
        <ActivityIndicator />
    )}

    The fix:

    1. Uses a useRef to track whether we've initiated a fetch for rates
    2. Shows loading state when per diem is enabled but rates are empty (indicating they're being loaded)
    3. Only shows empty state after we've confirmed rates are empty (after fetch completes)
    4. Updates the loading indicator to show when rates are loading in addition to when policy is loading

    This ensures that when cache is cleared, the component shows a loading indicator instead of briefly flashing the empty state, providing a better user experience.

    What alternative solutions did you explore? (Optional)

    Check if policy has per diem enabled before showing empty state: We could check policy?.arePerDiemRatesEnabled before showing empty state, but this alone doesn't distinguish between "loading" and "truly empty" states. We need to track fetch state.

  12. melvin-bot commented on Nov 13, 2025

    @melvin-bot

    📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

  13. 23 remaining items

  14. melvin-bot commented on Nov 26, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  15. melvin-bot commented on Nov 26, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.2.63-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-12-03. 🎊

    For reference, here are some details about the assignees on this issue:

    • @ahmedGaber93 requires payment through NewDot Manual Requests
    • @bernhardoj requires payment through NewDot Manual Requests
  16. melvin-bot commented on Nov 26, 2025

    @melvin-bot

    @ahmedGaber93 / @bernhardoj @RachCHopkins The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  17. added
    Daily
    and removed
    Weekly
    on Dec 2, 2025
  18. melvin-bot commented on Dec 3, 2025

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@RachCHopkins)

    • (if NewFeature) I have created a PR for any necessary HelpDot updates, or I confirmed no updates are necessary.
    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1986272881400271924/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  19. ahmedGaber93 commented on Dec 4, 2025

    @ahmedGaber93
    Contributor

    BugZero Checklist:

    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: https://github.com/Expensify/App/pull/54252/files#r2588366135

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A.

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Minor issue, I don't think we need a regression test here.

  20. melvin-bot commented on Dec 5, 2025

    @melvin-bot

    @RachCHopkins Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  21. RachCHopkins commented on Dec 7, 2025

    @RachCHopkins
    Contributor

    Payment Summary above is correct.

    Contributors to be paid via NewDot, and the Upwork post has been closed.

    🟢 to request payment.

  22. bernhardoj commented on Dec 8, 2025

    @bernhardoj
    Contributor

    Requested in ND.

  23. garrettmknight commented on Dec 18, 2025

    @garrettmknight
    Contributor

    $250 approved for @bernhardoj

  24. JmillsExpensify commented on Jan 4, 2026

    @JmillsExpensify
    Contributor

    $250 approved for @ahmedGaber93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions