forked from Rosetta/landing
Фикс ошибок
This commit is contained in:
36
src/main.tsx
36
src/main.tsx
@@ -2,6 +2,42 @@ import { createRoot } from 'react-dom/client'
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
import App from './App.tsx'
|
||||
|
||||
const PRELOAD_RELOAD_KEY = 'rosetta:preload-reload-at'
|
||||
const PRELOAD_RELOAD_COOLDOWN = 10_000
|
||||
|
||||
if (import.meta.env.PROD) {
|
||||
window.addEventListener('vite:preloadError', (event) => {
|
||||
let lastReload = 0
|
||||
|
||||
try {
|
||||
lastReload = Number(window.sessionStorage.getItem(PRELOAD_RELOAD_KEY) || 0)
|
||||
} catch {
|
||||
// Storage can be unavailable in restricted browser modes.
|
||||
}
|
||||
|
||||
if (Date.now() - lastReload < PRELOAD_RELOAD_COOLDOWN) {
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
try {
|
||||
window.sessionStorage.setItem(PRELOAD_RELOAD_KEY, String(Date.now()))
|
||||
} catch {
|
||||
// Reload recovery still works when storage is unavailable.
|
||||
}
|
||||
|
||||
window.location.reload()
|
||||
})
|
||||
|
||||
window.setTimeout(() => {
|
||||
try {
|
||||
window.sessionStorage.removeItem(PRELOAD_RELOAD_KEY)
|
||||
} catch {
|
||||
// Nothing to clear when storage is unavailable.
|
||||
}
|
||||
}, PRELOAD_RELOAD_COOLDOWN)
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<BrowserRouter>
|
||||
|
||||
Reference in New Issue
Block a user