From 832676bcfa07fafb6f7e91ad3198c751380ed773 Mon Sep 17 00:00:00 2001 From: Piotr Oleszczyk Date: Sun, 1 Mar 2026 00:54:54 +0100 Subject: [PATCH] fix(frontend): fix routines list crash and AI save redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Make Routine.steps optional in types.ts — list endpoint does not eager-load steps, so the field is absent from the JSON response - Guard routine.steps?.length ?? 0 in routines list page to prevent SSR TypeError when steps is undefined - Move redirect() outside try/catch in suggest save action; SvelteKit redirect throws internally and was being caught, causing a 500 error instead of navigating to the new routine Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/lib/types.ts | 2 +- frontend/src/routes/routines/+page.svelte | 2 +- frontend/src/routes/routines/suggest/+page.server.ts | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index b644a49..16aed33 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -181,7 +181,7 @@ export interface Routine { notes?: string; created_at: string; updated_at: string; - steps: RoutineStep[]; + steps?: RoutineStep[]; } export interface GroomingSchedule { diff --git a/frontend/src/routes/routines/+page.svelte b/frontend/src/routes/routines/+page.svelte index 28fa6fe..bea4647 100644 --- a/frontend/src/routes/routines/+page.svelte +++ b/frontend/src/routes/routines/+page.svelte @@ -47,7 +47,7 @@ {routine.part_of_day.toUpperCase()} - {routine.steps.length} steps + {routine.steps?.length ?? 0} steps {#if routine.notes} {routine.notes} diff --git a/frontend/src/routes/routines/suggest/+page.server.ts b/frontend/src/routes/routines/suggest/+page.server.ts index 026a352..f4d022a 100644 --- a/frontend/src/routes/routines/suggest/+page.server.ts +++ b/frontend/src/routes/routines/suggest/+page.server.ts @@ -74,8 +74,10 @@ export const actions: Actions = { return fail(400, { error: 'Nieprawidłowy format kroków.' }); } + let routineId: string; try { const routine = await createRoutine({ routine_date, part_of_day }); + routineId = routine.id; for (let i = 0; i < steps.length; i++) { const s = steps[i]; await addRoutineStep(routine.id, { @@ -87,10 +89,10 @@ export const actions: Actions = { region: s.region || undefined }); } - redirect(303, `/routines/${routine.id}`); } catch (e) { return fail(500, { error: (e as Error).message }); } + redirect(303, `/routines/${routineId}`); }, saveBatch: async ({ request }) => {