Skip to content

Web - Tab name shows the title of expense details page after closing the report #86087

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: 9.3.42-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #85473
Email or phone of affected tester (no customers): skdpmoskpskspskd@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

1 .Go to staging.new.expensify.com
2. Go to workspace chat.
3. Create two expenses.
4. Open the report.
5. Open any expense.
6. Close the RHP.

Expected Result:

Tab name will no longer show the title of expense details page.

Actual Result:

Tab name still shows the title of expense details page after closing the report.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Video.mp4

View all open jobs on GitHub

Activity

  1. added
    DeployBlockerCash
    Bug
    on Mar 23, 2026
  2. melvin-bot commented on Mar 23, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #85473

  3. melvin-bot commented on Mar 23, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. github-actions commented on Mar 23, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. OSBotify commented on Mar 23, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #85473 - "Remove useDocumentTitle cleanup to fix tab title race condition" by @MelvinBot (High confidence)
    Related Issues: This is a regression from the fix for #85352

    Recommendation: REVERT

    PR #85473 removed the cleanup function from the useDocumentTitle hook that was clearing the document title when a screen lost focus. While this fixed a race condition where titles were being cleared too early, it introduced the opposite problem: titles now persist after navigating away from a screen.

    When you close the expense detail RHP, the screen loses focus but the document title is never cleared, causing it to remain visible in the browser tab instead of reverting to the underlying page's title.

    Labels: Keeping DeployBlockerCash - this is a frontend App bug that requires reverting or fixing PR #85473

    📋 Detailed Analysis

    Evidence

    Verification

    The bug behavior matches exactly what would happen after removing the cleanup function:

    Before PR #85473:

    useFocusEffect(
        useCallback(() => {
            setPageTitle(title);
            return () => setPageTitle();  // Cleanup cleared title on blur
        }, [title]),
    );

    After PR #85473:

    useFocusEffect(
        useCallback(() => {
            setPageTitle(title);
            // No cleanup - title persists after navigation
        }, [title]),
    );

    Confirmed the current code in src/hooks/useDocumentTitle.ts has no cleanup function, matching the change from PR #85473.

    Root Cause

    PR #85473 was attempting to fix issue #85352 where document titles were being cleared prematurely due to a race condition with async title updates. The fix removed the cleanup function entirely, assuming that "each page simply sets its own title on focus."

    However, this assumption breaks for RHP (Right Hand Panel) screens. When you:

    1. Open an expense detail in the RHP → the RHP screen sets its title
    2. Close the RHP → the RHP screen loses focus but never clears its title
    3. The underlying page (workspace chat) does not re-set its title because it never lost focus
    4. Result: The expense detail title persists in the browser tab

    The fix needs to be more sophisticated - it should clear titles on blur, but do so in a way that doesn't race with the async title update pipeline.

  6. MelvinBot commented on Mar 23, 2026

    @MelvinBot
    Contributor

    Proposal

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

    After opening an expense detail in the RHP (Right Hand Panel) and then closing the RHP, the browser tab title still shows the expense detail page's title instead of reverting to the underlying page's title (e.g., the workspace chat name).

    What is the root cause of that problem?

    PR #85473 removed the cleanup function from the useDocumentTitle hook at src/hooks/useDocumentTitle.ts. Previously, the hook returned () => setPageTitle('') from useFocusEffect, which cleared the module-level currentPageTitle variable (in src/libs/UnreadIndicatorUpdater/updateUnread/index.ts:8) when a screen lost focus.

    Without cleanup, here's what happens:

    1. The underlying screen (e.g., workspace chat's ReportScreen) sets currentPageTitle to its title via useDocumentTitle
    2. The RHP opens, pushing onto the root stack. The RHP expense detail screen (also a ReportScreen) calls setPageTitle("Expense Detail"), overwriting currentPageTitle
    3. The RHP closes (popped from root stack). The expense detail screen unmounts, but since there's no cleanup function, currentPageTitle remains "Expense Detail"
    4. The underlying screen's useFocusEffect should re-fire on regaining focus to restore its title. However, the focus/blur event propagation chain (root stack → split navigator → central pane navigator → ReportScreen) relies on a series of async React.useEffect hooks in @react-navigation/core/src/useFocusEvents.tsx, and the useFocusEffect callback has a guard (if (isFocused) { return; } at useFocusEffect.tsx:82) that skips execution if the screen was never properly blurred
    5. The popstate listener (updateUnread/index.ts:51-53) and debounced triggerUnreadUpdate (UnreadIndicatorUpdater/index.ts:87-108) both call updateDocumentTitle(), but they only re-read the stale currentPageTitle — they don't know the correct page-specific title

    The net result: currentPageTitle permanently holds the RHP screen's title, and no mechanism resets it.

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

    Restore a non-disruptive cleanup in useDocumentTitle that clears currentPageTitle without triggering updateDocumentTitle():

    1. In src/libs/UnreadIndicatorUpdater/updateUnread/index.ts — add and export a clearPageTitle function:

      function clearPageTitle() {
          currentPageTitle = '';
      }
      

      This resets the module variable silently, without queuing a setTimeout to update document.title.

    2. In src/hooks/useDocumentTitle.ts — restore the cleanup using clearPageTitle:

      useFocusEffect(
          useCallback(() => {
              setPageTitle(title);
              return () => clearPageTitle();
          }, [title]),
      );
      

    Why this avoids the original race condition (issue #85352): The original cleanup called setPageTitle('') which triggered updateDocumentTitle() → setTimeout(() => { document.title = CONFIG.SITE_TITLE }). This async update could flash "New Expensify" if it executed between the cleanup and the new screen's title being set. By contrast, clearPageTitle() only clears the variable synchronously — no setTimeout is queued, so no "New Expensify" flash can occur.

    Why this fixes the bug: When the RHP's expense detail screen unmounts, its cleanup clears currentPageTitle. The underlying screen's useFocusEffect then fires and sets the correct title. Even if the focus event doesn't propagate correctly, the next updateDocumentTitle() call (from popstate or triggerUnreadUpdate) will fall back to CONFIG.SITE_TITLE instead of showing a stale expense detail title.

    What alternative solutions did you explore? (Optional)

    • Title stack approach: Maintain a stack of titles, pushing on focus and popping on blur. More robust but adds unnecessary complexity for what is essentially a cleanup oversight.
    • Navigation state listener: Update the title in the onStateChange handler in NavigationRoot.tsx. This would require mapping routes to titles, which duplicates the per-screen title logic.
    • Re-adding the original cleanup (return () => setPageTitle('')): This would re-introduce the "New Expensify" flash from issue [Due for payment 2026-03-31] Tab name does not persist after changing section and back to the previous section #85352.

    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.

  7. added
    Reviewing
    on Mar 23, 2026
  8. yuwenmemon commented on Mar 23, 2026

    @yuwenmemon
    Contributor

    @MelvinBot implement this

  9. MelvinBot commented on Mar 23, 2026

    @MelvinBot
    Contributor

    🤖 Draft PR created: #86141
    Please mark it as "Ready for review" when it is ready for review.

  10. MelvinBot commented on Mar 23, 2026

    @MelvinBot
    Contributor

    👋 I've created a draft PR implementing the proposed fix: #86142

    Instead of a straight revert (which would re-introduce the "New Expensify" title flash from #85352), this PR adds a new clearPageTitle() function that resets the module-level currentPageTitle variable synchronously without triggering updateDocumentTitle(). The useDocumentTitle hook's cleanup now calls clearPageTitle() instead of setPageTitle(''), avoiding the async setTimeout that caused the flash.

    This should fix both issues simultaneously — the stale RHP title (this issue) and the title flash (#85352).

    Please mark it as "Ready for review" when it is ready for review.

  11. added
    Daily
    and removed
    DeployBlockerCash
    Hourly
    on Mar 23, 2026
  12. yuwenmemon commented on Mar 23, 2026

    @yuwenmemon
    Contributor

    Not a blocker since this is already "buggy" in production. We should move forward with the proper fix above, without needing the rush to CP

  13. added
    Weekly
    and removed
    Daily
    on Mar 23, 2026
  14. added and removed
    Weekly
    on Apr 16, 2026
  15. melvin-bot commented on Apr 16, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @yuwenmemon eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  16. melvin-bot commented on Jun 12, 2026

    @melvin-bot

    @yuwenmemon, this Monthly task hasn't been acted upon in 6 weeks; closing.

    If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.

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

Metadata

Metadata

Assignees

Labels

BugEngineeringMonthlyNot a priorityReviewing

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions