Add clearPageTitle cleanup to useDocumentTitle to prevent stale tab title after RHP close#86141
Add clearPageTitle cleanup to useDocumentTitle to prevent stale tab title after RHP close#86141
Conversation
… after RHP close When the RHP expense detail screen was closed, the document title persisted because the useDocumentTitle hook had no cleanup function to clear currentPageTitle. This adds a clearPageTitle function that resets the module variable without triggering updateDocumentTitle(), avoiding the race condition that the original cleanup caused. Co-authored-by: Yuwen Memon <yuwenmemon@users.noreply.github.com>
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@mananjadhav Do you mine reviewing and testing this one? |
|
@eh2077 @yuwenmemon One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f908ae1236
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| function clearPageTitle() { | ||
| currentPageTitle = ''; |
There was a problem hiding this comment.
Avoid clearing shared title before deferred update executes
clearPageTitle() mutates the same currentPageTitle global that setPageTitle() relies on for its deferred setTimeout update. When two titled screens transition quickly (notably in split navigators), the outgoing screen’s focus cleanup can run after the incoming screen calls setPageTitle, so this cleanup resets currentPageTitle before the queued callback computes baseTitle. The tab title then falls back to CONFIG.SITE_TITLE and can stay wrong until another unread/title update occurs.
Useful? React with 👍 / 👎.
|
@MelvinBot I tried this change already and it doesn't work. There's a flicker and the focused tab doesn't have the title updated. Moreover the title stops updating for all the tabs and switching report. web-title.movI also feel we're missing the useDocumentTitle call in |
|
You're right on both counts. Good catch. The flicker / title stops updatingThe
The core issue is that Missing
|
|
@MelvinBot Can you force push or recreate the PR? @yuwenmemon May be you can request? |
|
I can't force push — that's not allowed per repository policy (it rewrites commit history). I could close this PR and create a new one with a revised approach, but I can only make code changes when directed by the PR author, an assignee, or an existing co-author. |
|
@MelvinBot implement the improvement you suggested above |
…uestReportPage The clearPageTitle approach caused a race condition with the debounced UnreadIndicatorUpdater, resulting in title flicker and titles stopping to update across tabs. Instead, keep the no-cleanup approach and add the missing useDocumentTitle call to SearchMoneyRequestReportPage so it properly sets the document title when focused. Co-authored-by: Yuwen Memon <yuwenmemon@users.noreply.github.com>
|
@QichenZhu Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
I've pushed a revised approach based on What changed:
Why this works better: Instead of trying to clean up stale titles on blur (which races with the async The PR now has a net change of only adding |
|
Okay @mananjadhav let's give it another spin |
Explanation of Change
PR #85473 removed the cleanup function from the
useDocumentTitlehook to fix a race condition where the tab title would briefly flash "New Expensify" during navigation. However, removing cleanup entirely means the document title set by an RHP screen persists after the RHP is closed, becausecurrentPageTitleis never cleared.This PR adds a new
clearPageTitle()function that resets thecurrentPageTitlemodule variable without triggeringupdateDocumentTitle(). TheuseDocumentTitlehook now returns this as its cleanup function. This avoids the original race condition (nosetTimeoutis queued during cleanup, so no "New Expensify" flash), while ensuring that when a screen loses focus, the stale title is cleared so it doesn't persist.Fixed Issues
$ #86087
PROPOSAL: #86087 (comment)
Tests
Offline tests
This change only affects the browser tab title (
document.title), which is a web-only, client-side operation. No offline-specific behavior changes.QA Steps
Same as tests above — reproducible on staging web (Chrome/Safari).
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
N/A — This change only affects the browser tab title (
document.title), which is web-only.Android: mWeb Chrome
N/A — Browser tab titles are visible but the change is purely cosmetic metadata.
iOS: Native
N/A — This change only affects the browser tab title (
document.title), which is web-only.iOS: mWeb Safari
N/A — Browser tab titles are visible but the change is purely cosmetic metadata.
MacOS: Chrome / Safari
N/A — Manual testing required to verify tab title persistence during navigation.