From 952535cc0a3e8157c762bd39652d5f8773a02939 Mon Sep 17 00:00:00 2001 From: tangxinyue <524779910@qq.com> Date: Fri, 24 Jul 2026 16:15:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=96=E6=B6=88=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E7=AB=AF=20assets=20=E6=99=BA=E8=83=BD=20fallback=20?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=20MIME=20=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E5=89=8D=E7=AB=AF=20chunk=20=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=90=8E=E5=8D=B8=E8=BD=BD=20SW=20=E5=B9=B6=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E6=97=B6=E9=97=B4=E6=88=B3=E5=88=B7=E6=96=B0=EF=BC=8C?= =?UTF-8?q?=E5=BD=BB=E5=BA=95=E8=A7=A3=E5=86=B3=E6=97=A7=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=AD=BB=E9=94=81=E7=99=BD=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/core/router/index.cjs | 17 ++++------------- src/router/index.js | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/service/core/router/index.cjs b/service/core/router/index.cjs index b9df3dc..ecb84d6 100644 --- a/service/core/router/index.cjs +++ b/service/core/router/index.cjs @@ -94,19 +94,10 @@ const matchFile = async (request, response) => { if (fs.existsSync(mappedPath)) { targetPath = mappedPath } else if (cleanPath.startsWith('/assets/')) { - const filename = cleanPath.split('/').pop() - const prefix = filename.split('-')[0] - const ext = filename.split('.').pop() - if (prefix && ext) { - const assetsDir = dist + '/assets' - if (fs.existsSync(assetsDir)) { - const files = fs.readdirSync(assetsDir) - const matchedFile = files.find(f => f.startsWith(prefix + '-') && f.endsWith('.' + ext)) - if (matchedFile) { - targetPath = assetsDir + '/' + matchedFile - } - } - } + response.writeHead(404, { 'Content-Type': 'text/plain' }) + response.end('Asset Not Found') + resolve(true) + return } } fs.readFile(targetPath, (err, file) => { diff --git a/src/router/index.js b/src/router/index.js index 9a5a03d..88f4efa 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -51,7 +51,23 @@ router.onError((error) => { const isReloaded = sessionStorage.getItem('chunk_reload_flag') if (!isReloaded) { sessionStorage.setItem('chunk_reload_flag', 'true') - window.location.reload() + + const forceReload = () => { + const url = new URL(window.location.href) + url.searchParams.set('t', Date.now()) + window.location.href = url.href + } + + if ('serviceWorker' in navigator) { + navigator.serviceWorker.getRegistrations().then(registrations => { + for (const registration of registrations) { + registration.unregister() + } + forceReload() + }).catch(() => { forceReload() }) + } else { + forceReload() + } } } })