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:
@@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user