From e39b03c272152c9b2b6278242b2e7e600764049a Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Tue, 21 Apr 2026 10:54:17 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20fix=20app=20shallow=20?= =?UTF-8?q?reload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The app was doing a shallow reload when user was coming from another tab and the user data was staled. We stop to block the app during the loading state, depend the response the app will manage correctly its states. --- CHANGELOG.md | 1 + .../e2e/__tests__/app-impress/doc-create.spec.ts | 2 +- .../impress/src/features/auth/components/Auth.tsx | 14 ++++++-------- .../impress/src/features/auth/hooks/useAuth.tsx | 10 +++++++++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd95d760..dabe99e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to - 🚸(frontend) redirect on current url tab after 401 #2197 - 🐛(frontend) abort check media status unmount #2194 - ✨(backend) order pinned documents by last updated at #2028 +- 🐛(frontend) fix app shallow reload #2231 - 🐛(frontend) fix interlinking modal clipping #2213 - 🛂(frontend) fix cannot manage member on small screen #2226 - 🐛(backend) load jwks url when OIDC_RS_PRIVATE_KEY_STR is set diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-create.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-create.spec.ts index eb3a8dcb..9c506d79 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-create.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-create.spec.ts @@ -52,7 +52,7 @@ test.describe('Doc Create', () => { ).toBeVisible(); }); - test('it creates a doc with link "/doc/new/', async ({ + test('it creates a doc with link "/docs/new/"', async ({ page, browserName, }) => { diff --git a/src/frontend/apps/impress/src/features/auth/components/Auth.tsx b/src/frontend/apps/impress/src/features/auth/components/Auth.tsx index 178474ab..13822151 100644 --- a/src/frontend/apps/impress/src/features/auth/components/Auth.tsx +++ b/src/frontend/apps/impress/src/features/auth/components/Auth.tsx @@ -18,32 +18,30 @@ import { FirstConnection } from './FirstConnection'; export const Auth = ({ children }: PropsWithChildren) => { const { - isLoading: isAuthLoading, + isAuthLoading, pathAllowed, - isFetchedAfterMount, authenticated, - fetchStatus, + hasInitiallyLoaded, user, } = useAuth(); - const isLoading = fetchStatus !== 'idle' || isAuthLoading; const [isRedirecting, setIsRedirecting] = useState(false); const { data: config } = useConfig(); const shouldTrySilentLogin = useMemo( () => !authenticated && !hasTrySilent() && - !isLoading && + !isAuthLoading && !isRedirecting && config?.FRONTEND_SILENT_LOGIN_ENABLED, [ authenticated, - isLoading, + isAuthLoading, isRedirecting, config?.FRONTEND_SILENT_LOGIN_ENABLED, ], ); const shouldTryLogin = - !authenticated && !isLoading && !isRedirecting && !pathAllowed; + !authenticated && !isAuthLoading && !isRedirecting && !pathAllowed; const { replace, pathname } = useRouter(); /** @@ -104,7 +102,7 @@ export const Auth = ({ children }: PropsWithChildren) => { ]); const shouldShowLoader = - (isLoading && !isFetchedAfterMount) || + !hasInitiallyLoaded || isRedirecting || (!authenticated && !pathAllowed) || shouldTrySilentLogin; diff --git a/src/frontend/apps/impress/src/features/auth/hooks/useAuth.tsx b/src/frontend/apps/impress/src/features/auth/hooks/useAuth.tsx index dc9054da..0663a99d 100644 --- a/src/frontend/apps/impress/src/features/auth/hooks/useAuth.tsx +++ b/src/frontend/apps/impress/src/features/auth/hooks/useAuth.tsx @@ -1,5 +1,5 @@ import { useRouter } from 'next/router'; -import { useEffect, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { useAnalytics } from '@/libs'; @@ -12,6 +12,12 @@ export const useAuth = () => { const { pathname } = useRouter(); const { trackEvent } = useAnalytics(); const [hasTracked, setHasTracked] = useState(authStates.isFetched); + const isAuthLoading = + authStates.fetchStatus !== 'idle' || authStates.isLoading; + const hasInitiallyLoaded = useRef(false); + if (authStates.isFetched) { + hasInitiallyLoaded.current = true; + } const [pathAllowed, setPathAllowed] = useState( !regexpUrlsAuth.some((regexp) => !!pathname.match(regexp)), ); @@ -35,6 +41,8 @@ export const useAuth = () => { user, authenticated: !!user && authStates.isSuccess, pathAllowed, + hasInitiallyLoaded: hasInitiallyLoaded.current, + isAuthLoading, ...authStates, }; };