Skip to content

Commit 50daf1c

Browse files
committed
Stop version-check auto-refresh loops on dashboard routes
1 parent 78daeeb commit 50daf1c

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

frontend/src/components/app/VersionCheck.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useEffect, useRef } from "react"
88
*/
99
export function VersionCheck() {
1010
const checkedRef = useRef(false)
11+
const VERSION_REFRESH_KEY = "fpai:version-refresh-attempt"
1112

1213
useEffect(() => {
1314
if (checkedRef.current) return
@@ -23,9 +24,27 @@ export function VersionCheck() {
2324
.then((r) => (r.ok ? r.json() : null))
2425
.then((data: { buildId?: string } | null) => {
2526
if (!data?.buildId) return
26-
if (data.buildId !== buildId) {
27-
const url = new URL(window.location.href)
28-
url.searchParams.set("_bust", String(Date.now()))
27+
if (data.buildId === buildId) {
28+
try {
29+
sessionStorage.removeItem(VERSION_REFRESH_KEY)
30+
} catch { }
31+
return
32+
}
33+
34+
const refreshPair = `${buildId}->${data.buildId}`
35+
let hasAttempted = false
36+
try {
37+
hasAttempted = sessionStorage.getItem(VERSION_REFRESH_KEY) === refreshPair
38+
} catch { }
39+
if (hasAttempted) return
40+
41+
try {
42+
sessionStorage.setItem(VERSION_REFRESH_KEY, refreshPair)
43+
} catch { }
44+
45+
const url = new URL(window.location.href)
46+
if (url.searchParams.get("_bust") !== data.buildId) {
47+
url.searchParams.set("_bust", data.buildId)
2948
window.location.replace(url.toString())
3049
}
3150
})

0 commit comments

Comments
 (0)