Files
shinkan-jinkendo/frontend/src/utils/lazyWithRetry.js
T
LarsandCursor 0431c9e160
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Successful in 49s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 18s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m43s
Reload once when a frontend chunk disappears after deploy.
A stale tab otherwise requests the previous hashed Dashboard bundle and shows the route error page.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-23 09:44:47 +01:00

29 lines
794 B
JavaScript

import { lazy } from 'react'
/**
* Lazy-Import mit Reload bei fehlendem Chunk (nach Deploy alte Hashes im Browser-Cache).
*/
const RELOAD_KEY = 'sj_chunk_reload'
export function lazyWithRetry(importFn) {
return lazy(() =>
importFn()
.then((mod) => {
sessionStorage.removeItem(RELOAD_KEY)
return mod
})
.catch((err) => {
const reloaded = sessionStorage.getItem(RELOAD_KEY)
if (!reloaded) {
sessionStorage.setItem(RELOAD_KEY, '1')
const url = new URL(window.location.href)
url.searchParams.set('sj_reload', String(Date.now()))
window.location.replace(url.toString())
return new Promise(() => {})
}
sessionStorage.removeItem(RELOAD_KEY)
throw err
}),
)
}