Limit activation readiness checks to blocking assets
This commit is contained in:
@@ -49,14 +49,13 @@
|
||||
return response ? response.json() : null;
|
||||
}
|
||||
|
||||
async function status(manifest, cache, { previous, activeLayout } = {}) {
|
||||
async function status(manifest, cache, { previous, activeLayout, offline = true } = {}) {
|
||||
const found = await Promise.all(blocking(manifest, previous, activeLayout).map(async path => {
|
||||
const response = await cache.match(url(path, manifest.files[path]));
|
||||
return !!response && response.headers.get('X-Asset-Hash') === manifest.files[path].h;
|
||||
}));
|
||||
const missing = found.filter(value => !value).length;
|
||||
const offline = await completeness(manifest, cache);
|
||||
return { ready: missing === 0, missing, version: manifest.buildTag, ...offline };
|
||||
return { ready: missing === 0, missing, version: manifest.buildTag, ...(offline ? await completeness(manifest, cache) : {}) };
|
||||
}
|
||||
|
||||
// All concurrent messages/layout jobs in this worker share six download slots.
|
||||
@@ -117,7 +116,7 @@
|
||||
}
|
||||
}));
|
||||
if (failure) throw failure;
|
||||
if (!groups && !all && !(await status(manifest, cache, { previous, activeLayout })).ready) throw new Error('Incomplete blocking assets');
|
||||
if (!groups && !all && !(await status(manifest, cache, { previous, activeLayout, offline: false })).ready) throw new Error('Incomplete blocking assets');
|
||||
return { refreshed: count, caches: 1 };
|
||||
}
|
||||
|
||||
@@ -125,12 +124,12 @@
|
||||
// Verified cache entries are the durable progress journal. Counters are rebuilt
|
||||
// after worker termination or browser eviction; never trust a stored ready bit.
|
||||
async function completeness(manifest, cache) {
|
||||
const missingFiles = [];
|
||||
for (const path of paths(manifest)) {
|
||||
const files = paths(manifest);
|
||||
const missingFiles = (await Promise.all(files.map(async path => {
|
||||
const response = await cache.match(url(path, manifest.files[path]));
|
||||
if (!response || response.headers.get('X-Asset-Hash') !== manifest.files[path].h) missingFiles.push(path);
|
||||
}
|
||||
const total = paths(manifest).length;
|
||||
return !response || response.headers.get('X-Asset-Hash') !== manifest.files[path].h ? path : null;
|
||||
}))).filter(Boolean);
|
||||
const total = files.length;
|
||||
return { offlineReady: missingFiles.length === 0, cached: total - missingFiles.length, total, missingFiles };
|
||||
}
|
||||
|
||||
@@ -167,7 +166,7 @@
|
||||
|
||||
async function commit(manifest, cache, { previousClients, activeLayout } = {}) {
|
||||
const old = await state(cache);
|
||||
if (!(await status(manifest, cache, { previous: old?.current, activeLayout })).ready) {
|
||||
if (!(await status(manifest, cache, { previous: old?.current, activeLayout, offline: false })).ready) {
|
||||
throw new Error('Incomplete blocking assets');
|
||||
}
|
||||
const sameBuild = old?.current?.buildTag === manifest.buildTag;
|
||||
|
||||
Reference in New Issue
Block a user