fix(version): skip mismatch toast in dev and harden sw fallback

This commit is contained in:
InfinityPacer
2026-04-12 23:30:03 +08:00
parent b44c0647f1
commit a0e7283ae6
2 changed files with 20 additions and 1 deletions

View File

@@ -12,7 +12,18 @@ declare let self: ServiceWorkerGlobalScope & {
// 缓存版本控制
const RESOURCE_VERSION = 'V2'
const CACHE_VERSION = `${__APP_VERSION__}-${__BUILD_TIME__}` // 开发环境下无法使用此环境变量,生产环境正常
// 开发态 dev-sw 可能拿不到 Vite define 注入;仅在开发环境做 dev 兜底
const hasAppVersion = typeof __APP_VERSION__ !== 'undefined'
const hasBuildTime = typeof __BUILD_TIME__ !== 'undefined'
const isDev = import.meta.env.DEV
if (!isDev && (!hasAppVersion || !hasBuildTime)) {
throw new Error('[SW] Missing __APP_VERSION__ or __BUILD_TIME__ in production build')
}
const appVersion = hasAppVersion ? __APP_VERSION__ : 'dev'
const buildTime = hasBuildTime ? __BUILD_TIME__ : 'dev'
const CACHE_VERSION = `${appVersion}-${buildTime}`
// 启用导航预载
navigationPreload.enable()

View File

@@ -23,6 +23,14 @@ export const useGlobalSettingsStore = defineStore('globalSettings', {
// 检查版本更新
if (result.FRONTEND_VERSION) {
const isBackendDev = Boolean(result.BACKEND_DEV)
const skipVersionCheck = import.meta.env.DEV || isBackendDev
if (skipVersionCheck) {
console.log('[VersionChecker] 开发环境下跳过版本一致性检查')
return
}
const { checkVersion } = useVersionChecker()
await checkVersion(result.FRONTEND_VERSION)
}