mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-13 04:06:57 +02:00
@vite-pwa/sveltekit does not auto-inject SW registration into SSR HTML. Add explicit registration via virtual:pwa-register in root layout onMount, inject webmanifest link via virtual:pwa-info, disable SvelteKit's built-in SW registration to avoid conflicts, and add required dependencies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
31 lines
668 B
Svelte
31 lines
668 B
Svelte
<script lang="ts">
|
|
import '../app.css';
|
|
import { onMount } from 'svelte';
|
|
import { pwaInfo } from 'virtual:pwa-info';
|
|
|
|
let { children } = $props();
|
|
|
|
onMount(async () => {
|
|
if (pwaInfo) {
|
|
const { registerSW } = await import('virtual:pwa-register');
|
|
registerSW({
|
|
immediate: true,
|
|
onRegistered(r: ServiceWorkerRegistration | undefined) {
|
|
console.log('SW Registered:', r);
|
|
},
|
|
onRegisterError(error: Error) {
|
|
console.log('SW registration error', error);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
const webManifest = $derived(pwaInfo ? pwaInfo.webManifest.linkTag : '');
|
|
</script>
|
|
|
|
<svelte:head>
|
|
{@html webManifest}
|
|
</svelte:head>
|
|
|
|
{@render children()}
|