From 586571e38e0d5258507f1ccd301e562f6150008f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 17 Jun 2026 21:24:47 +0000 Subject: [PATCH] Fix integrations page double-refresh on load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EnsureWorkspace treated /?view=integrations (and ?view=mcp) as a guest public page whenever there was no session object yet. During initial load the session is merely *pending*, not absent, so a logged-in user would: 1. render the page optimistically (isGuestPublicAppPage = true), then 2. have it swapped for the loading shell once the session resolved and org restore began (isRestoring), then 3. re-render the page once restore finished. That mount → loader → remount sequence is the visible "refresh twice". Gate isGuestPublicAppPage on !isSessionPending so the guest/public path is only taken once the session state is actually known. While pending we now show the loading shell, giving a single clean transition to the authenticated page. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01LShTAfUnV7zwXenzoH2dRE --- apps/web/components/ensure-workspace.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/web/components/ensure-workspace.tsx b/apps/web/components/ensure-workspace.tsx index 73218af2..62da5295 100644 --- a/apps/web/components/ensure-workspace.tsx +++ b/apps/web/components/ensure-workspace.tsx @@ -20,12 +20,17 @@ export function EnsureWorkspace({ children }: { children: React.ReactNode }) { const pathname = usePathname() const router = useRouter() const searchParams = useSearchParams() - const { session, organizations, isRestoring } = useAuth() + const { session, organizations, isRestoring, isSessionPending } = useAuth() const isPublicAppPage = pathname === "/" && ["integrations", "mcp"].includes(searchParams.get("view") ?? "") - const isGuestPublicAppPage = isPublicAppPage && !session + // Only treat this as a guest page once the session state is actually known. + // While the session is still pending we can't tell guest from logged-in, so + // rendering the public page optimistically here causes a logged-in user to + // see public content → loading shell → authenticated content (a double flash). + const isGuestPublicAppPage = + isPublicAppPage && !session && !isSessionPending const isOnboarding = pathname.startsWith("/onboarding") useEffect(() => {