From 8949b5b33ac940cddb79355dba94fd993fcd037d Mon Sep 17 00:00:00 2001 From: "prompt.ac/@jeffrey" Date: Fri, 24 Apr 2026 15:56:47 -0700 Subject: [PATCH] prompt + bios: drop SW module cache the moment a new deploy is detected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The piece-runs telemetry from the iPhone showed a familiar pattern: prompt.mjs's version poll surfaces "📦 New deployment detected: " within ~1s of cap loading, but the page is still running last-deploy's cached bios.mjs / disk.mjs (so the new bios's camera:debug events never get sent — and any rotation/UX fixes don't take effect). Now when prompt sees the version flip: - prompt.mjs send()s a new "sw:clear-cache" message to the main thread (it can't talk to the SW directly because it runs in a Web Worker). - bios.mjs catches it in receivedChange and calls navigator.serviceWorker.controller.postMessage("clearCache"), which the SW already knows how to handle (caches.delete(CACHE_NAME)). We don't auto-reload — that'd interrupt mid-task — but the cache eviction means the user's next manual reload pulls genuinely fresh modules instead of stale-while-revalidating for up to an hour. Should noticeably tighten the fix-deploy-test loop, especially on the iOS app where WKWebView's HTTP cache compounds with the SW's. --- system/public/aesthetic.computer/bios.mjs | 13 +++++++++++++ system/public/aesthetic.computer/disks/prompt.mjs | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/system/public/aesthetic.computer/bios.mjs b/system/public/aesthetic.computer/bios.mjs index 5a9d63a809..002de39809 100644 --- a/system/public/aesthetic.computer/bios.mjs +++ b/system/public/aesthetic.computer/bios.mjs @@ -5963,6 +5963,19 @@ async function boot(parsed, bpm = 60, resolution, debug) { return; } + if (type === "sw:clear-cache") { + // Forwarded from prompt.mjs's deployment poll. Tell the active SW + // to drop its module cache so the next page load fetches fresh + // bios.mjs / disk.mjs etc. instead of stale-while-revalidating. + try { + navigator.serviceWorker?.controller?.postMessage("clearCache"); + console.log("🔧 Main thread: requested SW cache clear"); + } catch (e) { + console.warn("🔧 Could not post clearCache to SW:", e); + } + return; + } + // Helper function to ensure fonts are loaded before use let fontsLoaded = false; async function ensureFontsLoaded() { diff --git a/system/public/aesthetic.computer/disks/prompt.mjs b/system/public/aesthetic.computer/disks/prompt.mjs index ce9645f136..fde3f7eae5 100644 --- a/system/public/aesthetic.computer/disks/prompt.mjs +++ b/system/public/aesthetic.computer/disks/prompt.mjs @@ -822,6 +822,19 @@ async function boot({ recentCommits = data.recentCommits || []; needsPaint(); console.log("📦 New deployment detected:", data.deployed); + // Tell the active service worker (via the main thread, since we + // run inside a Web Worker and don't have direct access to + // navigator.serviceWorker) to evict its module cache. The + // user's NEXT navigation/reload then pulls fresh bios.mjs + + // disk.mjs instead of stale-while-revalidating for up to an + // hour. We don't auto-reload here — that would interrupt the + // user mid-task — but the cache eviction makes a manual + // reload propagate the new build immediately. + try { + send({ type: "sw:clear-cache" }); + } catch (e) { + console.warn("📦 Could not request SW cache clear:", e); + } break; // Stop polling — update is available } catch (e) { if (e.name === "AbortError") break; -- 2.54.0