feat: add version polling and auto-reload on deploy
- Enable kit.version.pollInterval (60s) so SvelteKit detects new deploys via version.json - Add beforeNavigate guard that forces a full page reload when a new version is detected, preventing stale client-side state - Preload fonts, JS, and CSS for faster initial paint
This commit is contained in:
@@ -54,5 +54,7 @@ export const handle: Handle = async ({ event, resolve }) => {
|
||||
}
|
||||
}
|
||||
|
||||
return resolve(event);
|
||||
return resolve(event, {
|
||||
preload: ({ type }) => type === 'font' || type === 'js' || type === 'css'
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import Header from '$lib/components/layout/Header.svelte';
|
||||
import Footer from '$lib/components/layout/Footer.svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { updated } from '$app/stores';
|
||||
import { beforeNavigate } from '$app/navigation';
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
@@ -13,6 +15,12 @@
|
||||
let { data, children }: Props = $props();
|
||||
|
||||
const canonicalUrl = $derived(`https://marktvogt.de${$page.url.pathname}`);
|
||||
|
||||
beforeNavigate(({ willUnload, to }) => {
|
||||
if ($updated && !willUnload && to?.url) {
|
||||
location.href = to.url.href;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -3,7 +3,10 @@ import adapter from '@sveltejs/adapter-node';
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
kit: {
|
||||
adapter: adapter()
|
||||
adapter: adapter(),
|
||||
version: {
|
||||
pollInterval: 60_000
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user