fix: 取消易死锁的 sessionStorage 防抖限制,加入原生的 window.confirm 强制弹窗打破旧版页面与 SW 拦截死局
This commit is contained in:
parent
952535cc0a
commit
9d1fc36d63
|
|
@ -48,16 +48,16 @@ router.beforeEach(async (to, from, next) => {
|
||||||
router.onError((error) => {
|
router.onError((error) => {
|
||||||
const pattern = /Failed to fetch dynamically imported module|Importing a module script failed/i
|
const pattern = /Failed to fetch dynamically imported module|Importing a module script failed/i
|
||||||
if (pattern.test(error?.message || '')) {
|
if (pattern.test(error?.message || '')) {
|
||||||
const isReloaded = sessionStorage.getItem('chunk_reload_flag')
|
if (window._chunkErrorHandled) return
|
||||||
if (!isReloaded) {
|
window._chunkErrorHandled = true
|
||||||
sessionStorage.setItem('chunk_reload_flag', 'true')
|
|
||||||
|
const forceReload = () => {
|
||||||
const forceReload = () => {
|
const url = new URL(window.location.href)
|
||||||
const url = new URL(window.location.href)
|
url.searchParams.set('t', Date.now())
|
||||||
url.searchParams.set('t', Date.now())
|
window.location.href = url.href
|
||||||
window.location.href = url.href
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
const cleanAndReload = () => {
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.getRegistrations().then(registrations => {
|
navigator.serviceWorker.getRegistrations().then(registrations => {
|
||||||
for (const registration of registrations) {
|
for (const registration of registrations) {
|
||||||
|
|
@ -69,6 +69,12 @@ router.onError((error) => {
|
||||||
forceReload()
|
forceReload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (window.confirm('系统检测到版本更新,当前页面数据已过期。点击【确定】立即刷新体验最新版本!')) {
|
||||||
|
cleanAndReload()
|
||||||
|
} else {
|
||||||
|
window._chunkErrorHandled = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue