fix: replace window.location.reload with router.refresh on org switch to prevent hydration errors

This commit is contained in:
Usman Baig
2026-03-26 23:25:49 +01:00
parent 7c55e5f763
commit fba1f84ce5

View File

@@ -78,11 +78,17 @@ function LayoutInner({ children }: { children: React.ReactNode }) {
const handleSwitchOrganization = async (orgId: string | null) => { const handleSwitchOrganization = async (orgId: string | null) => {
if (!orgId) return if (!orgId) return
try { try {
setIsSwitchingOrg(true)
const { access_token } = await switchContext(orgId) const { access_token } = await switchContext(orgId)
await setSessionAction(access_token) await setSessionAction(access_token)
sessionStorage.setItem(ORG_SWITCH_KEY, 'true') router.refresh()
window.location.reload() // Allow time for server components to re-fetch with new auth
setTimeout(() => {
setIsSwitchingOrg(false)
router.push('/')
}, 600)
} catch (err) { } catch (err) {
setIsSwitchingOrg(false)
logger.error('Failed to switch organization', err) logger.error('Failed to switch organization', err)
} }
} }