fix: ensure home page data is serializable

Fixed serialization error by converting Directus SDK response objects to
plain JSON using JSON.parse(JSON.stringify()).

This resolves the error:
'Data returned from load while rendering / is not serializable:
Cannot stringify arbitrary non-POJOs (data.models)'

Also improved performance by using Promise.all to fetch models and videos
in parallel instead of sequentially.
This commit is contained in:
Valknar XXX
2025-10-28 23:41:40 +01:00
parent b883867b15
commit 10ab7a65df

View File

@@ -1,7 +1,13 @@
import { getFeaturedModels, getFeaturedVideos } from "$lib/services";
export async function load({ fetch }) {
const [models, videos] = await Promise.all([
getFeaturedModels(3, fetch),
getFeaturedVideos(3, fetch),
]);
// Ensure data is serializable by converting to plain JSON
return {
models: await getFeaturedModels(3, fetch),
videos: await getFeaturedVideos(3, fetch),
models: JSON.parse(JSON.stringify(models)),
videos: JSON.parse(JSON.stringify(videos)),
};
}