Object as children does not show any error or warning
When an object is passed as children to be rendered there's no warning or error and it doesn't render anything. I'm not sure if the issue is related to preact or fresh.
Example code
const activities = [
{ id: "1", name: "Wake up", date: new Date() },
{ id: "2", name: "Eat breakfast", date: new Date() },
{ id: "3", name: "Go to work", date: new Date() },
{ id: "4", name: "Go to sleep", date: new Date() },
];
export default function Home() {
return (
<ul>
{activities.map((activity) => (
<li key={activity.id}>{activity}</li>
))}
</ul>
);
}
Maybe define a custom handler for it? You can then get the value from props.data variable passed from the handler to the page. Or create a block scoped variable inside the page function and use the variable mentioned?
Fresh seems to not render something top level until it passed to a block scoped variable.
CMIIW.
It does render it if I just change the
<li key={activity.id}>{activity}</li>
to
<li key={activity.id}>{activity.name}</li>
I think it's correct to not render anything when an object is passed as children (not a literal), but the problem is there's no error or warning so it's confusing what's wrong.
It does render it if I just change the
<li key={activity.id}>{activity}</li>to
<li key={activity.id}>{activity.name}</li>I think it's correct to not render anything when an object is passed as children (not a literal), but the problem is there's no error or warning so it's confusing what's wrong.
Ah now I get it. Yeah I agree with you, should've thrown an error or some sort.
The rendering inconsistency is a bug in preact-render-to-string. See https://github.com/preactjs/preact-render-to-string/issues/245 for that issue.
#761 will fix this being silently ignored. Instead an error will be thrown / warning logged in the future.
@lucacasonato this should be published as part of preact-render-to-string 5.2.5