[app] CalmRefresh: Register the worker in the app and offer the waiting version; e2e publishes a real second one
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
"svelte-check": "4.7.6",
|
||||
"typescript": "5.9.3",
|
||||
"vite": "6.4.3",
|
||||
"vite-plugin-pwa": "1.3.0"
|
||||
"vite-plugin-pwa": "1.3.0",
|
||||
"workbox-window": "7.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)} />
|
||||
|
||||
Vendored
+1
@@ -1,2 +1,3 @@
|
||||
/// <reference types="svelte" />
|
||||
/// <reference types="vite/client" />
|
||||
/// <reference types="vite-plugin-pwa/client" />
|
||||
|
||||
@@ -66,9 +66,10 @@ export default defineConfig({
|
||||
// Never swap a running app silently. A new worker waits until the player
|
||||
// is offered a calm refresh control (CLAUDE.md §8, GAP_ANALYSIS G0.10).
|
||||
registerType: 'prompt',
|
||||
// An emitted registerSW.js file, not an inline snippet: the CSP has no
|
||||
// 'unsafe-inline' for scripts.
|
||||
injectRegister: 'script',
|
||||
// The app registers the worker itself through virtual:pwa-register, so it hears
|
||||
// when a new version is waiting (calm-refresh.md U1). Bundled, not inline: the
|
||||
// CSP has no 'unsafe-inline' for scripts.
|
||||
injectRegister: false,
|
||||
manifest: {
|
||||
// The web manifest: one of the three places the name lives, built from
|
||||
// the constants in @rosea/schema so the strings exist only there.
|
||||
|
||||
Reference in New Issue
Block a user