fix: precache only stable shell paths so SW install survives a production build
This commit is contained in:
+5
-1
@@ -1,5 +1,9 @@
|
||||
const CACHE = 'director-v1';
|
||||
const SHELL = ['/', '/index.html', '/src/main.js', '/src/styles.css'];
|
||||
// Precache only stable, build-invariant navigation paths. Hashed asset
|
||||
// bundles (/assets/*) are cached at runtime on first online load by the
|
||||
// cache-first fetch handler below. (Follow-up: generate a full precache
|
||||
// list from the Vite build manifest for cold-offline-before-first-visit.)
|
||||
const SHELL = ['/', '/index.html'];
|
||||
|
||||
self.addEventListener('install', (e) => {
|
||||
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting()));
|
||||
|
||||
+7
-1
@@ -18,9 +18,15 @@ describe('PWA wiring', () => {
|
||||
expect(js).toContain('serviceWorker');
|
||||
expect(js).toContain("register('/sw.js')");
|
||||
});
|
||||
it('service worker precaches the shell', () => {
|
||||
it('service worker precaches only stable shell paths', () => {
|
||||
const sw = readFileSync('public/sw.js', 'utf8');
|
||||
expect(sw).toContain('addEventListener');
|
||||
expect(sw).toContain('caches');
|
||||
const shellMatch = sw.match(/SHELL\s*=\s*\[([^\]]*)\]/);
|
||||
expect(shellMatch).not.toBe(null);
|
||||
const shell = shellMatch[1];
|
||||
expect(shell).toContain("'/'");
|
||||
expect(shell).toContain("'/index.html'");
|
||||
expect(shell).not.toContain('/src/');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user