fix: prevent infinite reload loop on stale build recovery
Use sessionStorage guard so the hard reload only fires once. If the reload doesn't fix it (CDN still serving stale JS), fall through gracefully instead of looping forever.
This commit is contained in:
@@ -26,8 +26,15 @@ function AuthCallbackContent() {
|
|||||||
try {
|
try {
|
||||||
result = await exchangeAuthCode(code, codeVerifier, redirectUri)
|
result = await exchangeAuthCode(code, codeVerifier, redirectUri)
|
||||||
} catch {
|
} catch {
|
||||||
// * Stale build — cached JS has old Server Action hashes. Hard reload to fix.
|
// * Stale build — cached JS has old Server Action hashes. Hard reload once to fix.
|
||||||
window.location.reload()
|
const key = 'pulse_reload_for_stale_build'
|
||||||
|
if (!sessionStorage.getItem(key)) {
|
||||||
|
sessionStorage.setItem(key, '1')
|
||||||
|
window.location.reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sessionStorage.removeItem(key)
|
||||||
|
setError('Something went wrong. Please try logging in again.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (result.success && result.user) {
|
if (result.success && result.user) {
|
||||||
|
|||||||
@@ -135,10 +135,19 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
let session: Awaited<ReturnType<typeof getSessionAction>> = null
|
let session: Awaited<ReturnType<typeof getSessionAction>> = null
|
||||||
try {
|
try {
|
||||||
session = await getSessionAction()
|
session = await getSessionAction()
|
||||||
|
sessionStorage.removeItem('pulse_reload_for_stale_build')
|
||||||
} catch {
|
} catch {
|
||||||
// * Stale build — browser has cached JS with old Server Action hashes.
|
// * Stale build — browser has cached JS with old Server Action hashes.
|
||||||
// * Force a hard reload to fetch fresh bundles from the server.
|
// * Force a hard reload once to fetch fresh bundles. Guard prevents infinite loop.
|
||||||
window.location.reload()
|
const key = 'pulse_reload_for_stale_build'
|
||||||
|
if (!sessionStorage.getItem(key)) {
|
||||||
|
sessionStorage.setItem(key, '1')
|
||||||
|
window.location.reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sessionStorage.removeItem(key)
|
||||||
|
// * Reload didn't fix it — treat as no session
|
||||||
|
setLoading(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +162,14 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
try {
|
try {
|
||||||
session = await getSessionAction()
|
session = await getSessionAction()
|
||||||
} catch {
|
} catch {
|
||||||
window.location.reload()
|
const key = 'pulse_reload_for_stale_build'
|
||||||
|
if (!sessionStorage.getItem(key)) {
|
||||||
|
sessionStorage.setItem(key, '1')
|
||||||
|
window.location.reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sessionStorage.removeItem(key)
|
||||||
|
setLoading(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user