diff --git a/Dockerfile b/Dockerfile index 5102afd28..d7de72f01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 31bb6e884..f49788294 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -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'); diff --git a/svelte.config.js b/svelte.config.js index 0e5f9097b..19b397286 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -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: {