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 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user