Yeni versiyon güncelleme uyarısı çıkacak

This commit is contained in:
Sedat Öztürk 2025-09-22 23:30:50 +03:00
parent c5f3a65304
commit 51208b8693
3 changed files with 9 additions and 5 deletions

View file

@ -1,4 +1,3 @@
import { ROUTES_ENUM } from '@/routes/route.constant'
import { useState, useEffect } from 'react'
import { HiOutlineRefresh, HiX } from 'react-icons/hi'
import { useStoreActions } from '@/store'
@ -50,10 +49,16 @@ const UpdateNotifier = () => {
reg.waiting.postMessage({ type: 'SKIP_WAITING' })
reg.waiting.addEventListener('statechange', (e: any) => {
if (e.target.state === 'activated') {
if (newVersion) {
setUiVersion(newVersion) // ✅ Storedaki versiyonu güncelle
}
window.location.reload()
}
})
} else {
if (newVersion) {
setUiVersion(newVersion) // ✅ Direkt güncelle
}
window.location.reload()
}
})

View file

@ -3,7 +3,6 @@ import { registerSW } from 'virtual:pwa-register'
export const registerServiceWorker = () => {
registerSW({
immediate: true, // Yeni SW hemen yüklensin
onNeedRefresh() {
const event = new CustomEvent('sw-update-available')
window.dispatchEvent(event)

View file

@ -22,7 +22,7 @@ export default defineConfig(async ({ mode }) => {
mode === 'production'
? VitePWA({
// Deploy'dan sonra otomatik güncelle
registerType: 'autoUpdate',
registerType: 'prompt',
// Kayıt kodunu otomatik enjekte et (virtual:pwa-register yazmadan da çalışır)
injectRegister: 'auto',
// Dev ortamında SW'yi aç, prod'da kapalı tut (build edilmiş SW prod'da zaten aktif olur)
@ -37,10 +37,10 @@ export default defineConfig(async ({ mode }) => {
// EN KRİTİK: yeni SW beklemeden kontrolü alsın
clientsClaim: true,
skipWaiting: true,
skipWaiting: false,
// Eski workbox cache'lerini temizle
cleanupOutdatedCaches: mode === 'production',
cleanupOutdatedCaches: true,
// SPA fallback'i API çağrılarına uygulama
navigateFallbackDenylist: [/^\/api\//],