refactor(pwa): replace custom service workers with Vite PWA plugin and centralize offline page

Remove hand-written sw.js, offline.html, and manifest.json from todo/skilltree/zitare web apps
in favor of the Workbox-based service worker generated by @vite-pwa/sveltekit. This fixes an
issue where the custom SW could get stuck serving the offline fallback page even when the server
was reachable. Also extracts the duplicated offline page (~80 lines each across 19 apps) into a
shared OfflinePage component in @manacore/shared-ui with 3 props (appName, offlineMessage,
accentColor), reducing each app's offline route to an 8-line wrapper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-22 18:16:43 +01:00
parent 93a7c90f4f
commit 9bdb997394
33 changed files with 262 additions and 2023 deletions

View file

@ -42,6 +42,7 @@
"@manacore/shared-icons": "workspace:*",
"@manacore/shared-tailwind": "workspace:*",
"@manacore/shared-theme": "workspace:*",
"@manacore/shared-ui": "workspace:^",
"@manacore/shared-utils": "workspace:*",
"idb": "^8.0.0",
"svelte-i18n": "^4.0.1",

View file

@ -7,12 +7,8 @@
<!-- Favicon -->
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<!-- PWA Manifest -->
<link rel="manifest" href="/manifest.json" />
<!-- Theme Color -->
<meta name="theme-color" content="#10b981" />
<meta name="msapplication-TileColor" content="#10b981" />
<!-- PWA -->
<meta name="mobile-web-app-capable" content="yes" />

View file

@ -1,78 +1,9 @@
<script lang="ts">
import { onMount } from 'svelte';
let isOnline = $state(false);
onMount(() => {
isOnline = navigator.onLine;
const handleOnline = () => {
isOnline = true;
setTimeout(() => {
window.location.href = '/';
}, 1000);
};
const handleOffline = () => {
isOnline = false;
};
window.addEventListener('online', handleOnline);
window.addEventListener('offline', handleOffline);
return () => {
window.removeEventListener('online', handleOnline);
window.removeEventListener('offline', handleOffline);
};
});
import { OfflinePage } from '@manacore/shared-ui';
</script>
<svelte:head>
<title>Offline - SkillTree</title>
</svelte:head>
<div class="min-h-screen bg-slate-900 flex items-center justify-center px-4">
<div class="text-center max-w-md">
<div class="mb-8">
<svg class="w-24 h-24 mx-auto text-slate-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M18.364 5.636a9 9 0 010 12.728m0 0l-2.829-2.829m2.829 2.829L21 21M15.536 8.464a5 5 0 010 7.072m0 0l-2.829-2.829m-4.243 2.829a5 5 0 01-.354-7.072L8.95 7.636m1.414 5.657L7.535 16.12m8.485 0a5 5 0 01-7.07 0" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 3l18 18" />
</svg>
</div>
<h1 class="text-2xl font-bold text-white mb-4">
{isOnline ? 'Verbindung wiederhergestellt!' : 'Du bist offline'}
</h1>
<p class="text-slate-400 mb-8">
{#if isOnline}
Du wirst gleich weitergeleitet...
{:else}
Deine Skills werden lokal gespeichert und sind offline verfügbar.
{/if}
</p>
{#if !isOnline}
<div class="space-y-4">
<a href="/" class="inline-flex items-center justify-center px-6 py-3 bg-violet-600 hover:bg-violet-700 text-white font-medium rounded-lg transition-colors">
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
</svg>
Zur Startseite
</a>
<button onclick={() => window.location.reload()} class="block w-full px-6 py-3 text-slate-400 hover:text-white transition-colors">
Erneut versuchen
</button>
</div>
{:else}
<div class="flex items-center justify-center text-green-400">
<svg class="w-5 h-5 mr-2 animate-spin" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
Weiterleitung...
</div>
{/if}
</div>
</div>
<OfflinePage
appName="SkillTree"
offlineMessage="Deine Skills werden lokal gespeichert und sind offline verfügbar."
accentColor="#7c3aed"
/>

View file

@ -1,21 +0,0 @@
{
"name": "SkillTree",
"short_name": "SkillTree",
"description": "Track your skills like a game. Level up in real life.",
"start_url": "/",
"display": "standalone",
"background_color": "#111827",
"theme_color": "#10b981",
"icons": [
{
"src": "/icons/icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/icons/icon-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}