Skip to content

Commit 93a08a2

Browse files
committed
Fix Blazor version mismatch error on deployment
1 parent fa2c2c7 commit 93a08a2

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

cloud/src/LrmCloud.Web/wwwroot/js/app.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,21 @@ window.lrmServiceWorker = {
266266
}
267267
},
268268

269-
applyUpdate: function() {
269+
applyUpdate: async function() {
270+
// Clear all caches to ensure fresh load (prevents stale DLL issues)
271+
try {
272+
const cacheNames = await caches.keys();
273+
await Promise.all(cacheNames.map(name => caches.delete(name)));
274+
console.log('[SW] Caches cleared for update');
275+
} catch (err) {
276+
console.error('[SW] Failed to clear caches:', err);
277+
}
278+
270279
if (this.registration?.waiting) {
271280
this.registration.waiting.postMessage({ type: 'SKIP_WAITING' });
272-
// Fallback reload in case controllerchange doesn't fire
273-
setTimeout(() => window.location.reload(), 1000);
274281
}
282+
// Reload after cache clear (controllerchange may also trigger reload)
283+
window.location.reload();
275284
}
276285
};
277286

cloud/src/LrmCloud.Web/wwwroot/service-worker.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,29 @@ self.addEventListener('fetch', (event) => {
102102
return;
103103
}
104104

105+
// For Blazor framework files - NETWORK FIRST (critical for version consistency)
106+
// Blazor uses integrity hashes; serving stale DLLs causes hash mismatch errors
107+
if (url.pathname.includes('/_framework/')) {
108+
event.respondWith(
109+
fetch(request)
110+
.then((response) => {
111+
if (response.ok) {
112+
const responseClone = response.clone();
113+
caches.open(CACHE_NAME)
114+
.then((cache) => cache.put(request, responseClone));
115+
}
116+
return response;
117+
})
118+
.catch(() => caches.match(request)) // Fallback to cache only if offline
119+
);
120+
return;
121+
}
122+
105123
// For static assets, try cache first, then network
106124
if (
107125
url.pathname.includes('/css/') ||
108126
url.pathname.includes('/js/') ||
109127
url.pathname.includes('/_content/') ||
110-
url.pathname.includes('/_framework/') ||
111128
url.pathname.endsWith('.png') ||
112129
url.pathname.endsWith('.ico') ||
113130
url.pathname.endsWith('.json') ||

0 commit comments

Comments
 (0)