Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/pages/signin/SignInModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ function SignInModal() {
signinPageRef.current?.navigateBack();
}}
/>
<SignInPageBase ref={signinPageRef} />
{/* Do not reset the browser tab title here: this modal can open over an anonymous-accessible report,
and resetting would wrongly clear that report's tab title. The title reset only applies to the
public root sign-in screen. */}
<SignInPageBase
ref={signinPageRef}
shouldResetTabTitle={false}
/>
</ScreenWrapper>
);
}
Expand Down
32 changes: 27 additions & 5 deletions src/pages/signin/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ThemeProvider from '@components/ThemeProvider';
import ThemeStylesProvider from '@components/ThemeStylesContextProvider';

import useAndroidBackButtonHandler from '@hooks/useAndroidBackButtonHandler';
import useDocumentTitle from '@hooks/useDocumentTitle';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand Down Expand Up @@ -49,6 +50,11 @@ import ValidateCodeForm from './ValidateCodeForm';

type SignInPageProps = {
ref?: Ref<SignInPageRef>;

/** Whether to reset the browser tab title to the site title ("New Expensify") on focus. Only the public root
* sign-in screen should do this. The reusable SignInModal instance renders this same component over an
* anonymous-accessible report, where resetting would wrongly clear that report's tab title. */
shouldResetTabTitle?: boolean;
};

type SignInPageRef = {
Expand Down Expand Up @@ -163,7 +169,16 @@ function getRenderOptions({
};
}

function SignInPage({ref}: SignInPageProps) {
// Renders nothing; on focus it resets the browser tab title so it falls back to the site title ("New Expensify").
// Authenticated pages set a page-specific title via useDocumentTitle, but nothing clears it on logout, so the tab
// would otherwise stay stuck on the last visited page's title. Mounted only on the public root sign-in screen
// (see SignInPage's shouldResetTabTitle), never in the reusable SignInModal instance. This is a no-op on native.
function ResetTabTitleOnFocus() {
useDocumentTitle('');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope the title reset to the root sign-in screen

When an anonymous user is viewing an anonymous-accessible report and clicks Sign in, signOutAndRedirectToSignIn() opens ROUTES.SIGN_IN_MODAL, and SignInModal renders this same SignInPage component. Since useDocumentTitle('') runs from the focused modal too, it clears the report’s document title back to CONFIG.SITE_TITLE even though the user has not landed on the signed-out root screen. Please gate this reset to the public root sign-in route or keep it out of the reusable modal instance.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's an issue but @MelvinBot let’s implement it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — implemented in f63d144. This is a real issue: SignInModal renders this same SignInPage component, so useDocumentTitle('') fired from the modal too and would clear the underlying anonymous-accessible report's tab title.

Rather than reintroduce route-name coupling, I gated the reset behind an explicit prop:

  • Added a shouldResetTabTitle prop to SignInPage (defaults to true), and moved the useDocumentTitle('') call into a tiny ResetTabTitleOnFocus child that only mounts when the prop is true. Threaded the prop through SignInPageWrapper and the WithTheme HOC.
  • SignInModal now passes shouldResetTabTitle={false}, so the reusable modal instance never touches the title.
  • The public root sign-in screen (registered in PublicScreens) renders the default export with no prop, so it keeps resetting to "New Expensify" on logout as intended.

Local checks: oxfmt, ESLint (0 errors), tsc typecheck (clean; the one BaseGenericTooltip TS2590 error is pre-existing and unrelated), React Compiler compliance, and the PublicSignInPageRootUrlTest + SessionTest suites all pass.

return null;
}

function SignInPage({ref, shouldResetTabTitle = true}: SignInPageProps) {
const {translate, formatPhoneNumber} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const signInPageLayoutRef = useRef<SignInPageLayoutRef>(null);
Expand Down Expand Up @@ -322,6 +337,7 @@ function SignInPage({ref}: SignInPageProps) {

return (
<ColorSchemeWrapper>
{shouldResetTabTitle && <ResetTabTitleOnFocus />}
<CustomStatusBarAndBackground isNested />
<LoginProvider>
<SignInPageLayout
Expand Down Expand Up @@ -363,7 +379,7 @@ function SignInPage({ref}: SignInPageProps) {
);
}

function SignInPageWrapper({ref}: SignInPageProps) {
function SignInPageWrapper({ref, shouldResetTabTitle}: SignInPageProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const safeAreaInsets = useSafeAreaInsets();
Expand All @@ -378,15 +394,18 @@ function SignInPageWrapper({ref}: SignInPageProps) {
style={[styles.signInPage, StyleUtils.getPlatformSafeAreaPadding({...safeAreaInsets, bottom: 0, top: isInNarrowPaneModal ? 0 : safeAreaInsets.top}, 1)]}
testID="SignInPageWrapper"
>
<SignInPage ref={ref} />
<SignInPage
ref={ref}
shouldResetTabTitle={shouldResetTabTitle}
/>
</ScreenWrapper>
);
}

// WithTheme is a HOC that provides theme-related contexts (e.g. to the SignInPageWrapper component since these contexts are required for variable declarations).
// The sign-in page always uses the dark theme, but respects the user's contrast preference (nvp_preferredTheme) which is preserved on sign-out.
function WithTheme(Component: React.ComponentType<SignInPageProps>) {
function ThemedComponent({ref}: SignInPageProps) {
function ThemedComponent({ref, shouldResetTabTitle}: SignInPageProps) {
const [preferredTheme] = useOnyx(ONYXKEYS.PREFERRED_THEME);
const [highContrastIntent] = useOnyx(ONYXKEYS.SIGN_IN_HIGH_CONTRAST_INTENT);
const contrastThemes: string[] = [CONST.THEME.DARK_CONTRAST, CONST.THEME.LIGHT_CONTRAST, CONST.THEME.SYSTEM_CONTRAST];
Expand All @@ -397,7 +416,10 @@ function WithTheme(Component: React.ComponentType<SignInPageProps>) {
<ThemeProvider theme={signInTheme}>
<ThemeStylesProvider>
<HTMLEngineProvider>
<Component ref={ref} />
<Component
ref={ref}
shouldResetTabTitle={shouldResetTabTitle}
/>
</HTMLEngineProvider>
</ThemeStylesProvider>
</ThemeProvider>
Expand Down
Loading