-
server console: "Warning: Only plain objects can be passed to Client Components from Server Components. Date objects are not supported. <... dateObj={Date}>" "next": "^13.1.6", (appDir) structure. The date is getting passed to the client component and displayed, so the warning is confusing. (My problem is that I am seeing how much of Crossfilter( d3.js, dc.js, crossfilter.js) can be moved onto server components and after parsing a 250,000 line .csv file on a server component, I pass the data to a client component and get the server console "warning" 250,000 times) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi, The problem is that to pass data from Server Components to Client Components, the data must be serialisable. In our world, frontend development, typically this means that the "data" has to be compliant to JSON transformations, that is from JavaScript Objects/Primitives to Strings. The Date object is special because if you pass a let obj = {d : new Date()}
JSON.stringify(obj) // '{"d":"2023-02-20T07:22:59.163Z"}'
let str =JSON.stringify(obj)
JSON.parse(str) // {d: '2023-02-20T07:22:59.163Z'} And that's why it can't be passed as props from Server to Client, that's what this error is telling you. Other notables are functions and closures, which cannot possibly be reconstructed client side. |
Beta Was this translation helpful? Give feedback.
-
Hi, can you also see this object, I checked and there is no date object here: console.log(inspect(products, true, 100, true))
output:
[
[Object: null prototype] {
id: '16',
title: 'Colour ',
uptitle: null,
published_at: '2024-02-25T21:44:13.360Z',
forward_link: null,
position: null,
services: [
[Object: null prototype] { id: '8', title: 'Acrylic Colour' },
[length]: 1
],
thumbnail: [Object: null prototype] {
alt: null,
file: [Object: null prototype] {
hash: 'e45d664e',
ext: 'png',
mime: 'image/png'
}
}
},
[length]: 1
] I get these warnings regarding this object:
|
Beta Was this translation helpful? Give feedback.
Hi,
The problem is that to pass data from Server Components to Client Components, the data must be serialisable.
In our world, frontend development, typically this means that the "data" has to be compliant to JSON transformations, that is from JavaScript Objects/Primitives to Strings.
The Date object is special because if you pass a
Date
object, into JSON.stringify, it gets casted as a string, but then if you try to recover the Date object by parsing, you get a string anyway, so the Date object is destroyed in the process.