🐛(frontend) fix app shallow reload

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.
This commit is contained in:
Anthony LC 2026-04-21 10:54:17 +02:00
parent 3cc9655574
commit e39b03c272
No known key found for this signature in database
4 changed files with 17 additions and 10 deletions

View file

@ -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

View file

@ -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,
}) => {

View file

@ -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;

View file

@ -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<boolean>(
!regexpUrlsAuth.some((regexp) => !!pathname.match(regexp)),
);
@ -35,6 +41,8 @@ export const useAuth = () => {
user,
authenticated: !!user && authStates.isSuccess,
pathAllowed,
hasInitiallyLoaded: hasInitiallyLoaded.current,
isAuthLoading,
...authStates,
};
};