[app] CalmRefresh: Register the worker in the app and offer the waiting version; e2e publishes a real second one

This commit is contained in:
2026-11-02 01:18:09 +01:00
parent beea8eaa10
commit a5480d2877
8 changed files with 111 additions and 10 deletions
+11 -1
View File
@@ -3,6 +3,7 @@
import { createIdentity } from '@rosea/identity';
import { openStorage } from '@rosea/storage';
import { Shell, type RoseWiring, type SunsetWiring } from '@rosea/ui';
import { registerSW } from 'virtual:pwa-register';
import { version } from '../package.json';
// Bundled at build time, so the letter is precached and opens offline (letter-slot.md L1).
import letter from '../../../docs/LETTER.md?raw';
@@ -75,6 +76,15 @@
setTimeout(() => URL.revokeObjectURL(url), 10_000);
}
// --- A new version waiting (calm-refresh.md) ----------------------------
// The worker is registered here so the page hears when a new version has installed
// and waits. It is offered, never swapped in by itself (U2).
let updateReady = $state(false);
const updateSW = registerSW({
onNeedRefresh: () => (updateReady = true),
onRegisterError: (error: unknown) => console.error('update: the service worker could not be registered', error)
});
const rose: RoseWiring = {
identity: () => (identity ??= findIdentity()),
loadCare: () => storage.loadCare(),
@@ -94,4 +104,4 @@
};
</script>
<Shell {letter} {sunset} {rose} />
<Shell {letter} {sunset} {rose} {updateReady} onrefresh={() => void updateSW(true)} />