Merge pull request #13832 from Ithanil/svelte_versioning

feat: Handle frontend updates according to Svelte docs
This commit is contained in:
Tim Jaeryang Baek 2025-05-14 17:19:32 +04:00 committed by GitHub
commit 4959e91fa7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 1 deletions

View File

@ -26,6 +26,9 @@ ARG BUILD_HASH
WORKDIR /app
# to store git revision in build
RUN apk add --no-cache git
COPY package.json package-lock.json ./
RUN npm ci

View File

@ -49,6 +49,16 @@
import AppSidebar from '$lib/components/app/AppSidebar.svelte';
import { chatCompletion } from '$lib/apis/openai';
import { beforeNavigate } from '$app/navigation';
import { updated } from '$app/state';
// handle frontend updates (https://svelte.dev/docs/kit/configuration#version)
beforeNavigate(({ willUnload, to }) => {
if (updated.current && !willUnload && to?.url) {
location.href = to.url.href;
}
});
setContext('i18n', i18n);
const bc = new BroadcastChannel('active-tab-channel');

View File

@ -1,4 +1,5 @@
import adapter from '@sveltejs/adapter-static';
import * as child_process from 'node:child_process';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
@ -14,7 +15,12 @@ const config = {
pages: 'build',
assets: 'build',
fallback: 'index.html'
})
}),
// poll for new version name every 60 seconds (to trigger reload mechanic in +layout.svelte)
version: {
name: child_process.execSync('git rev-parse HEAD').toString().trim(),
pollInterval: 60000
}
},
vitePlugin: {
// inspector: {