From e366b44bba8a42348cff820933dab35cefa48414 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Tue, 20 Jan 2026 19:44:52 +0100 Subject: [PATCH] fix: include server load data in universal load for recipe page title The +page.server.ts fetches recipe data and strips HTML tags server-side to avoid bundling cheerio in the client. However, the universal load in +page.ts wasn't including this data in its return value. Fixed by: 1. Having +page.server.ts fetch the recipe directly (since it runs before +page.ts and can't access its data via parent()) 2. Adding the `data` parameter to +page.ts and spreading it in the return Co-Authored-By: Claude Opus 4.5 --- .../[name]/+page.server.ts | 23 ++++++++++++++----- .../[recipeLang=recipeLang]/[name]/+page.ts | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/routes/[recipeLang=recipeLang]/[name]/+page.server.ts b/src/routes/[recipeLang=recipeLang]/[name]/+page.server.ts index f8f609c..01228d2 100644 --- a/src/routes/[recipeLang=recipeLang]/[name]/+page.server.ts +++ b/src/routes/[recipeLang=recipeLang]/[name]/+page.server.ts @@ -1,13 +1,24 @@ import { redirect, error } from '@sveltejs/kit'; import { stripHtmlTags } from '$lib/js/stripHtmlTags'; -export async function load({ parent }) { - // Get data from universal load function - const data = await parent(); +export async function load({ params, fetch }) { + // Fetch recipe data to strip HTML tags server-side + // This avoids bundling cheerio in the client bundle + const isEnglish = params.recipeLang === 'recipes'; + const apiBase = isEnglish ? '/api/recipes' : '/api/rezepte'; - // Strip HTML tags server-side to avoid bundling cheerio in client - const strippedName = stripHtmlTags(data.name); - const strippedDescription = stripHtmlTags(data.description); + const res = await fetch(`${apiBase}/items/${params.name}`); + if (!res.ok) { + // Let the universal load function handle the error + return { + strippedName: '', + strippedDescription: '', + }; + } + + const item = await res.json(); + const strippedName = stripHtmlTags(item.name); + const strippedDescription = stripHtmlTags(item.description); return { strippedName, diff --git a/src/routes/[recipeLang=recipeLang]/[name]/+page.ts b/src/routes/[recipeLang=recipeLang]/[name]/+page.ts index b4d1d84..a27221f 100644 --- a/src/routes/[recipeLang=recipeLang]/[name]/+page.ts +++ b/src/routes/[recipeLang=recipeLang]/[name]/+page.ts @@ -1,7 +1,7 @@ import { error } from "@sveltejs/kit"; import { generateRecipeJsonLd } from '$lib/js/recipeJsonLd'; -export async function load({ fetch, params, url}) { +export async function load({ fetch, params, url, data }) { const isEnglish = params.recipeLang === 'recipes'; const apiBase = isEnglish ? '/api/recipes' : '/api/rezepte'; @@ -119,6 +119,7 @@ export async function load({ fetch, params, url}) { const germanShortName = isEnglish ? (item.germanShortName || '') : item.short_name; return { + ...data, // Include server load data (strippedName, strippedDescription) ...item, isFavorite, multiplier,