Skip to content

The Open Source DocuSign Alternative.

fix: resolve error flash on page refresh (#2606)

David Nguyen8d97f1dcfab6
diff --git a/apps/remix/app/components/general/refresh-on-focus.tsx b/apps/remix/app/components/general/refresh-on-focus.tsx
deleted file mode 100644
index bf8f7a68a..000000000
--- a/apps/remix/app/components/general/refresh-on-focus.tsx
+++ /dev/null
@@ -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;
-};
diff --git a/packages/lib/client-only/providers/session.tsx b/packages/lib/client-only/providers/session.tsx
index 493dce7b1..83232d267 100644
--- a/packages/lib/client-only/providers/session.tsx
+++ b/packages/lib/client-only/providers/session.tsx
@@ -71,11 +71,28 @@ export const SessionProvider = ({ children, initialSession }: SessionProviderPro
const organisations = await trpc.organisation.internal.getOrganisationSession
.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
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({
session: newSession.session,
user: newSession.user,