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.
14 lines
392 B
TypeScript
14 lines
392 B
TypeScript
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: JSON.parse(JSON.stringify(models)),
|
|
videos: JSON.parse(JSON.stringify(videos)),
|
|
};
|
|
}
|