I have a
Blogcollection that I want to write content into, but when I console log the content into the react component, I only get back elements of type
text. I took the relevant code from the website template for this (corresponding collection in template is Posts). What could the issue be?
I think the LexicalEditor config might need adjusting?
https://github.com/payloadcms/payload/blob/beta/templates/website/src/payload.config.ts#L87it does not load all the defaultFeatures
oh,
https://github.com/payloadcms/payload/blob/beta/templates/website/src/payload/collections/Posts/index.ts#L67it does load the
rootFeatureshere
can you show us your
Blogscollection config?
I'm heading to bed soon so maybe Alessio can save the day, but the config looks correct
when you highlight over First heading, does it tell you it's "heading 1" in the toolbar?
yes
If you include the TreeViewFeature in your editor, what does the tree look like?
like this?
in my content field in the tabs for the Blog schema
Yep
ah 1 sec
lemme reload
here ya go
it seems right to me
Ohhhhh I didn't see that you were looping through the children
If you inspect
post.content.rootthe tree should be correct?
basically, you were looping through all the heading nodes and grabbing the text nodes inside the heading node
oh 💀
ok but i thought the component from website template should handle that
<RichText
className="lg:grid lg:grid-cols-subgrid col-start-1 col-span-3 grid-rows-[1fr]"
content={post.content}
enableGutter={false}
/>I'm not very familiar with the website template, it's possible it's handing it
yes
serializeLexical({ nodes: content?.root?.children })}this is the function it uses
you were mapping over children
content.root.children, yes
this is the serializeLexical component if you need
If you need a more complete example:
https://github.com/tyteen4a03/payload-lexical-renderer-examplethis is what it was originally
(it doesn't do tables yet but I'm working on that)
thank you
ill have a look later
gotta jet now
thanks so much for the help
have a good night :)
im slightly confused by the Pages and Posts collections on this template
I don't need a Pages collection...
If you're sure, you can delete it
yep
so i was debugging my richtext component
const RichText: React.FC<Props> = ({
className,
content,
enableGutter = true,
enableProse = true,
}) => {
if (!content) {
return null
}
if (content &&
!Array.isArray(content) &&
typeof content === 'object' &&
'root' in content)
{
const serialized = serializeLexical({ nodes: content.root?.children })
console.log(serialized.props)
}
return (
<div
className={cn(
{
'container ': enableGutter,
'max-w-none': !enableGutter,
'mx-auto prose dark:prose-invert ': enableProse,
},
className,
)}
>
{content &&
!Array.isArray(content) &&
typeof content === 'object' &&
'root' in content &&
serializeLexical({ nodes: content.root?.children })}
</div>
)
}
export default RichTextin the if statement before the
returnat the end
it correctly prints out the serialized JSX object
but when I load the page
it looks like the rendering worked 😅 but it doesn't look like a h1 or a h3
if you know what i mean
give my renderer a try
I think i fixed it 😅 (had to do with just supplying a custom classname)
btw how is your renderer different to the website template one?
just curious
Not much, it's just more spread out and it has examples dealing with blocks (but not relationships yet)
Star
Discord
online
Get dedicated engineering support directly from the Payload team.