Private
Public Access
1
0

Fix $state runtime error: rename rune stores to .svelte.ts

$state runes only work in .svelte and .svelte.ts files. The toasts and
theme stores used $state in plain .ts files, which compiled in dev but
crashed in production SSR. Renamed and updated all imports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Catherine Renelle
2026-02-26 01:33:15 -05:00
parent 1ec64e4ad5
commit 062832a1e3
9 changed files with 7 additions and 7 deletions
+35
View File
@@ -0,0 +1,35 @@
let nextId = 0;
export type ToastType = 'success' | 'error' | 'warning' | 'info';
export type Toast = {
id: number;
type: ToastType;
message: string;
};
let toasts = $state<Toast[]>([]);
export function getToasts(): Toast[] {
return toasts;
}
export function addToast(type: ToastType, message: string, duration = 4000): number {
const id = nextId++;
toasts.push({ id, type, message });
if (duration > 0) {
setTimeout(() => removeToast(id), duration);
}
return id;
}
export function removeToast(id: number) {
toasts = toasts.filter((t) => t.id !== id);
}
export const toast = {
success: (msg: string, duration?: number) => addToast('success', msg, duration),
error: (msg: string, duration?: number) => addToast('error', msg, duration ?? 6000),
warning: (msg: string, duration?: number) => addToast('warning', msg, duration),
info: (msg: string, duration?: number) => addToast('info', msg, duration)
};