fix: pass app version via server load instead of Vite define

The Svelte 5 SSR compiler was optimizing away the __APP_VERSION__
constant set via Vite's define, causing the version to be missing
from the production footer. Use a +layout.server.ts load function
to pass the version from package.json instead.

Also bumps version to 0.1.6.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Frederic Cabassut
2026-03-06 07:18:59 +01:00
co-authored by Claude Opus 4.6
parent 3b3a1b4ff0
commit a9779c93aa
5 changed files with 8 additions and 13 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "crumbs",
"private": true,
"version": "0.1.5",
"version": "0.1.6",
"type": "module",
"scripts": {
"dev": "vite dev",
-2
View File
@@ -1,8 +1,6 @@
// See https://svelte.dev/docs/kit/types#app.d.ts
// for information about these interfaces
declare global {
const __APP_VERSION__: string;
namespace App {
// interface Error {}
// interface Locals {}
+5
View File
@@ -0,0 +1,5 @@
import { version } from '../../package.json';
export function load() {
return { appVersion: version };
}
+2 -4
View File
@@ -6,9 +6,7 @@
import { loadNotes } from '$lib/stores/notes.js';
import { onMount } from 'svelte';
const appVersion = __APP_VERSION__;
let { children } = $props();
let { data, children } = $props();
let sidebarOpen = $state(false);
onMount(() => {
@@ -27,7 +25,7 @@
</main>
<footer class="pb-4 pt-8 text-center text-xs text-gray-400 lg:ml-64">
Crumbs by Bretzel v{appVersion} &mdash; made with 🥨 in Strasbourg
Crumbs by Bretzel v{data.appVersion} &mdash; made with 🥨 in Strasbourg
</footer>
<Toast />
-6
View File
@@ -1,15 +1,9 @@
import { readFileSync } from 'node:fs';
import { sveltekit } from '@sveltejs/kit/vite';
import { SvelteKitPWA } from '@vite-pwa/sveltekit';
import tailwindcss from '@tailwindcss/vite';
import { defineConfig } from 'vite';
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify(pkg.version)
},
plugins: [
tailwindcss(),
sveltekit(),