diff --git a/components/dashboard/src/data/featureflag-query.ts b/components/dashboard/src/data/featureflag-query.ts index 84502dcb51d9a8..3c6cfdf34d9c31 100644 --- a/components/dashboard/src/data/featureflag-query.ts +++ b/components/dashboard/src/data/featureflag-query.ts @@ -24,6 +24,7 @@ const featureFlags = { enableDedicatedOnboardingFlow: false, usageDownload: false, phoneVerificationByCall: false, + doRetryUserLoader: true, }; export const useFeatureFlag = (featureFlag: keyof typeof featureFlags) => { diff --git a/components/dashboard/src/hooks/use-user-loader.ts b/components/dashboard/src/hooks/use-user-loader.ts index 0c2724f19092f8..918b4346803b38 100644 --- a/components/dashboard/src/hooks/use-user-loader.ts +++ b/components/dashboard/src/hooks/use-user-loader.ts @@ -11,9 +11,12 @@ import { trackLocation } from "../Analytics"; import { refreshSearchData } from "../components/RepositoryFinder"; import { useQuery } from "@tanstack/react-query"; import { noPersistence } from "../data/setup"; +import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; +import { useFeatureFlag } from "../data/featureflag-query"; export const useUserLoader = () => { const { user, setUser } = useContext(UserContext); + const doRetryUserLoader = useFeatureFlag("doRetryUserLoader"); // For now, we're using the user context to store the user, but letting react-query handle the loading // In the future, we should remove the user context and use react-query to access the user @@ -27,8 +30,15 @@ export const useUserLoader = () => { // We'll let an ErrorBoundary catch the error useErrorBoundary: true, // It's important we don't retry as we want to show the login screen as quickly as possible if a 401 - // TODO: In the future we can consider retrying for non 401 errors - retry: false, + retry: (_failureCount: number, error: Error & { code?: number }) => { + if (!doRetryUserLoader) { + return false; + } + return error.code !== ErrorCodes.NOT_AUTHENTICATED; + }, + // docs: https://tanstack.com/query/v4/docs/react/guides/query-retries + // backoff by doubling, max. 10s + retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000), cacheTime: 1000 * 60 * 60 * 1, // 1 hour staleTime: 1000 * 60 * 60 * 1, // 1 hour onSuccess: (loadedUser) => {