fix: 取消易死锁的 sessionStorage 防抖限制,加入原生的 window.confirm 强制弹窗打破旧版页面与 SW 拦截死局

This commit is contained in:
tangxinyue 2026-07-24 16:23:31 +08:00
parent 952535cc0a
commit 9d1fc36d63
1 changed files with 15 additions and 9 deletions

View File

@ -48,16 +48,16 @@ router.beforeEach(async (to, from, next) => {
router.onError((error) => {
const pattern = /Failed to fetch dynamically imported module|Importing a module script failed/i
if (pattern.test(error?.message || '')) {
const isReloaded = sessionStorage.getItem('chunk_reload_flag')
if (!isReloaded) {
sessionStorage.setItem('chunk_reload_flag', 'true')
if (window._chunkErrorHandled) return
window._chunkErrorHandled = true
const forceReload = () => {
const url = new URL(window.location.href)
url.searchParams.set('t', Date.now())
window.location.href = url.href
}
const forceReload = () => {
const url = new URL(window.location.href)
url.searchParams.set('t', Date.now())
window.location.href = url.href
}
const cleanAndReload = () => {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then(registrations => {
for (const registration of registrations) {
@ -69,6 +69,12 @@ router.onError((error) => {
forceReload()
}
}
if (window.confirm('系统检测到版本更新,当前页面数据已过期。点击【确定】立即刷新体验最新版本!')) {
cleanAndReload()
} else {
window._chunkErrorHandled = false
}
}
})