diff --git a/src/app/intro/intro-client.tsx b/src/app/intro/intro-client.tsx index 7fd3d68..d0f2062 100644 --- a/src/app/intro/intro-client.tsx +++ b/src/app/intro/intro-client.tsx @@ -59,20 +59,28 @@ export default function IntroClient() { const handleOpenSteps = useCallback(() => { setIsStepsOpen(true); if (typeof window !== "undefined") { - const url = new URL(window.location.href); - url.searchParams.set("steps", "open"); - window.history.replaceState({ steps: "open" }, "", url.toString()); + try { + const url = new URL(window.location.href); + url.searchParams.set("steps", "open"); + window.history.replaceState({ steps: "open" }, "", url.toString()); + } catch (e) { + console.warn("Could not update URL history for steps:", e); + } } }, []); const handleCloseSteps = useCallback(() => { setIsStepsOpen(false); if (typeof window !== "undefined") { - const params = new URLSearchParams(window.location.search); - if (params.get("steps") === "open") { - const url = new URL(window.location.href); - url.searchParams.delete("steps"); - window.history.replaceState({}, "", url.toString()); + try { + const params = new URLSearchParams(window.location.search); + if (params.get("steps") === "open") { + const url = new URL(window.location.href); + url.searchParams.delete("steps"); + window.history.replaceState({}, "", url.toString()); + } + } catch (e) { + console.warn("Could not clear URL history for steps:", e); } } }, []); @@ -90,23 +98,26 @@ export default function IntroClient() { return; } + // If user is not authenticated yet, open onboarding steps immediately (0ms delay) + if (!authBridge.isAuthenticated()) { + handleOpenSteps(); + return; + } + setIsSubmitting(true); try { - if (!authBridge.isAuthenticated()) { - const token = await authBridge.ensureToken(); - if (!token) { - console.warn( - "No token from bridge – opening intro onboarding steps", - ); - handleOpenSteps(); - return; - } - } - let profileResponse = profile; try { - const { data: freshProfile } = await refetch(); + // Race refetch against a 2-second timeout so slow network never hangs the button + const refetchPromise = refetch(); + const timeoutPromise = new Promise<{ data?: undefined }>((resolve) => + setTimeout(() => resolve({ data: undefined }), 2000), + ); + const { data: freshProfile } = await Promise.race([ + refetchPromise, + timeoutPromise, + ]); profileResponse = freshProfile ?? profile; } catch (refetchError) { console.warn(