From fba1f84ce510b4dd242cc00d8ddfe3d391365afa Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Thu, 26 Mar 2026 23:25:49 +0100 Subject: [PATCH] fix: replace window.location.reload with router.refresh on org switch to prevent hydration errors --- app/layout-content.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/layout-content.tsx b/app/layout-content.tsx index ddf2ccf..3e0d959 100644 --- a/app/layout-content.tsx +++ b/app/layout-content.tsx @@ -78,11 +78,17 @@ function LayoutInner({ children }: { children: React.ReactNode }) { const handleSwitchOrganization = async (orgId: string | null) => { if (!orgId) return try { + setIsSwitchingOrg(true) const { access_token } = await switchContext(orgId) await setSessionAction(access_token) - sessionStorage.setItem(ORG_SWITCH_KEY, 'true') - window.location.reload() + router.refresh() + // Allow time for server components to re-fetch with new auth + setTimeout(() => { + setIsSwitchingOrg(false) + router.push('/') + }, 600) } catch (err) { + setIsSwitchingOrg(false) logger.error('Failed to switch organization', err) } }