From 5d191d40b50be9d5449c2262b987598a5a5c4e73 Mon Sep 17 00:00:00 2001 From: maxgfr <25312957+maxgfr@users.noreply.github.com> Date: Mon, 2 Nov 2026 10:29:31 +0100 Subject: [PATCH] chore(playground): keep loading grammars when Cache Storage refuses maxgfr.github.io is one origin shared by every project site, so its storage quota can be filled by another site, and private windows may refuse Cache Storage altogether. A rejected caches.open, match or put made the grammar load fail even though the wasm had been fetched. The cache is now best effort: any of those failing falls back to the network copy. No package change: the playground is only deployed with the site. --- site/playground/worker.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/site/playground/worker.js b/site/playground/worker.js index ebce1b0..f59e087 100644 --- a/site/playground/worker.js +++ b/site/playground/worker.js @@ -58,12 +58,15 @@ async function fetchWasm(name) { const url = new URL(`./grammars/${name}`, self.location.href).href; // Cached so a second repo — and every reload — skips the download entirely. // Grammar wasm is immutable per release, so there is nothing to invalidate. - const cache = self.caches ? await caches.open(GRAMMAR_CACHE) : null; - const hit = cache ? await cache.match(url) : null; + // The cache is best effort: maxgfr.github.io is one origin shared by many + // sites, so its quota can be full, and private windows may refuse Cache + // Storage outright. Either way the grammar still loads from the network. + const cache = self.caches ? await caches.open(GRAMMAR_CACHE).catch(() => null) : null; + const hit = cache ? await cache.match(url).catch(() => undefined) : undefined; if (hit) return new Uint8Array(await hit.arrayBuffer()); const response = await fetch(url); if (!response.ok) throw new Error(`grammar ${name}: HTTP ${response.status}`); - if (cache) await cache.put(url, response.clone()); + if (cache) await cache.put(url, response.clone()).catch(() => {}); return new Uint8Array(await response.arrayBuffer()); }