mirror of
https://github.com/documenso/documenso.git
synced 2026-06-22 04:12:06 +10:00
fix: resolve error flash on page refresh (#2606)
This commit is contained in:
@@ -1,26 +0,0 @@
|
|||||||
import { useCallback, useEffect } from 'react';
|
|
||||||
|
|
||||||
import { useRevalidator } from 'react-router';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Not really used anymore, this causes random 500s when the user refreshes while this occurs.
|
|
||||||
*/
|
|
||||||
export const RefreshOnFocus = () => {
|
|
||||||
const { revalidate, state } = useRevalidator();
|
|
||||||
|
|
||||||
const onFocus = useCallback(() => {
|
|
||||||
if (state === 'idle') {
|
|
||||||
void revalidate();
|
|
||||||
}
|
|
||||||
}, [revalidate]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
window.addEventListener('focus', onFocus);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('focus', onFocus);
|
|
||||||
};
|
|
||||||
}, [onFocus]);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
@@ -71,11 +71,28 @@ export const SessionProvider = ({ children, initialSession }: SessionProviderPro
|
|||||||
|
|
||||||
const organisations = await trpc.organisation.internal.getOrganisationSession
|
const organisations = await trpc.organisation.internal.getOrganisationSession
|
||||||
.query(undefined, SKIP_QUERY_BATCH_META.trpc)
|
.query(undefined, SKIP_QUERY_BATCH_META.trpc)
|
||||||
.catch(() => {
|
.catch((e) => {
|
||||||
|
const errorMessage = typeof e.message === 'string' ? e.message.toLowerCase() : '';
|
||||||
|
|
||||||
|
const isNetworkError =
|
||||||
|
errorMessage.includes('networkerror') || errorMessage.includes('failed to fetch');
|
||||||
|
|
||||||
|
// If the error is a transient network/abort error (e.g. page refresh while
|
||||||
|
// fetch was in-flight), return null to signal we should skip the state update.
|
||||||
|
if (isNetworkError) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Todo: (RR7) Log
|
// Todo: (RR7) Log
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Skip session update if the organisation fetch was aborted due to a transient
|
||||||
|
// network error (e.g. page refresh while fetch was in-flight).
|
||||||
|
if (organisations === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setSession({
|
setSession({
|
||||||
session: newSession.session,
|
session: newSession.session,
|
||||||
user: newSession.user,
|
user: newSession.user,
|
||||||
|
|||||||
Reference in New Issue
Block a user