Fix service worker cache preventing code updates and change fallback URL
All checks were successful
Build and Push Docker Images / docker (push) Successful in 44s
All checks were successful
Build and Push Docker Images / docker (push) Successful in 44s
- Bumped service worker cache version to v2 to force cache invalidation - Added activate event to explicitly clear old caches - Enhanced service worker logging with update checking - Changed API fallback URL from localhost:3001 to https://puffinoffset.com/api This fixes the issue where new code deployments were not being used due to service worker caching the old JavaScript with the timing bug. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8d9f65868a
commit
5ec24af338
18
public/sw.js
18
public/sw.js
@ -1,4 +1,4 @@
|
||||
const CACHE_NAME = 'puffin-calculator-v1';
|
||||
const CACHE_NAME = 'puffin-calculator-v2'; // Bumped to clear old cached code
|
||||
const urlsToCache = [
|
||||
'/',
|
||||
'/mobile-app',
|
||||
@ -21,6 +21,22 @@ self.addEventListener('install', (event) => {
|
||||
);
|
||||
});
|
||||
|
||||
// Activate event - clear old caches
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames.map((cacheName) => {
|
||||
if (cacheName !== CACHE_NAME) {
|
||||
console.log('Clearing old cache:', cacheName);
|
||||
return caches.delete(cacheName);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Fetch event - serve from cache when offline
|
||||
self.addEventListener('fetch', (event) => {
|
||||
event.respondWith(
|
||||
|
||||
@ -10,8 +10,8 @@ const getApiBaseUrl = (): string => {
|
||||
return window.env.API_BASE_URL;
|
||||
}
|
||||
|
||||
// Fall back to build-time env or default
|
||||
return import.meta.env.VITE_API_BASE_URL || 'http://localhost:3001';
|
||||
// Fall back to build-time env or production default
|
||||
return import.meta.env.VITE_API_BASE_URL || 'https://puffinoffset.com/api';
|
||||
};
|
||||
|
||||
export interface CreateCheckoutSessionParams {
|
||||
|
||||
12
src/main.tsx
12
src/main.tsx
@ -9,10 +9,18 @@ if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/sw.js')
|
||||
.then((registration) => {
|
||||
console.log('SW registered: ', registration);
|
||||
console.log('✅ Service Worker registered:', registration);
|
||||
|
||||
// Check for updates immediately
|
||||
registration.update();
|
||||
|
||||
// Log when a new service worker is waiting
|
||||
if (registration.waiting) {
|
||||
console.log('⚠️ New service worker waiting. Reload page to activate.');
|
||||
}
|
||||
})
|
||||
.catch((registrationError) => {
|
||||
console.log('SW registration failed: ', registrationError);
|
||||
console.error('❌ SW registration failed:', registrationError);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user