Nuxt 3 API Endpoint Data Lost During Server-Client Transfer Despite Valid Server-Side Data
I'm experiencing a puzzling issue with my Nuxt 3 application where data is being lost during the transfer from server to client, despite the data being valid on the server side.
And an API endpoint that returns this data:
On the client side, I'm fetching the data:
Setup
I have a view model that handles data transformation:And an API endpoint that returns this data:
On the client side, I'm fetching the data:
The Weird Part
- The server-side logs show the data is valid and structured correctly
- If I explicitly return a plain object with the same properties within the API endpoint, instead of `return item.toJSON()` it works:```typescript// server/api/items/[id].get.ts...// This worksreturn {id: item.toJSON().id,title: item.toJSON().title,description: item.toJSON().description};```
- Returning item.toJSON() results in a `null` response on the client side
- I've tried various serialization approaches (superjson, JSON.stringify/parse) but the issue persists
