Browse Source

fix(intro): remove blocking token wait on submit for instant onboarding transition

staging
Muhammad A. Ghorbani 2 weeks ago
parent
commit
72db3ba162
  1. 31
      src/app/intro/intro-client.tsx

31
src/app/intro/intro-client.tsx

@ -59,21 +59,29 @@ export default function IntroClient() {
const handleOpenSteps = useCallback(() => { const handleOpenSteps = useCallback(() => {
setIsStepsOpen(true); setIsStepsOpen(true);
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
try {
const url = new URL(window.location.href); const url = new URL(window.location.href);
url.searchParams.set("steps", "open"); url.searchParams.set("steps", "open");
window.history.replaceState({ steps: "open" }, "", url.toString()); window.history.replaceState({ steps: "open" }, "", url.toString());
} catch (e) {
console.warn("Could not update URL history for steps:", e);
}
} }
}, []); }, []);
const handleCloseSteps = useCallback(() => { const handleCloseSteps = useCallback(() => {
setIsStepsOpen(false); setIsStepsOpen(false);
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
try {
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
if (params.get("steps") === "open") { if (params.get("steps") === "open") {
const url = new URL(window.location.href); const url = new URL(window.location.href);
url.searchParams.delete("steps"); url.searchParams.delete("steps");
window.history.replaceState({}, "", url.toString()); 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; return;
} }
setIsSubmitting(true);
try {
// If user is not authenticated yet, open onboarding steps immediately (0ms delay)
if (!authBridge.isAuthenticated()) { if (!authBridge.isAuthenticated()) {
const token = await authBridge.ensureToken();
if (!token) {
console.warn(
"No token from bridge – opening intro onboarding steps",
);
handleOpenSteps(); handleOpenSteps();
return; return;
} }
}
setIsSubmitting(true);
try {
let profileResponse = profile; let profileResponse = profile;
try { 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; profileResponse = freshProfile ?? profile;
} catch (refetchError) { } catch (refetchError) {
console.warn( console.warn(

Loading…
Cancel
Save