-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trying out your renderer with Lexical playground elements throws an error #6
Comments
@dohomi We did not encounter this issue as the configuration of the editor inside payload does not allow to add these elements (I think). Could you provide me the full editor content state so I can reproduce this issue 🙏 |
hey @schaschjan this is how my editor JSON looks like: export const lexicalPreJson = {
root: {
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "Hello World",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "heading",
version: 1,
tag: "h1"
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "Hello World",
type: "text",
version: 1
}
],
direction: "ltr",
format: "right",
indent: 0,
type: "heading",
version: 1,
tag: "h2"
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "this is a simple ",
type: "text",
version: 1
},
{
detail: 0,
format: 1,
mode: "normal",
style: "",
text: "hello",
type: "text",
version: 1
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: " ",
type: "text",
version: 1
},
{
detail: 0,
format: 10,
mode: "normal",
style: "",
text: "world",
type: "text",
version: 1
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: " example!!",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [],
direction: null,
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "Ordered list:",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "first",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 1
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "second",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 2
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "third",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 3
}
],
direction: "ltr",
format: "",
indent: 0,
type: "list",
version: 1,
listType: "number",
start: 1,
tag: "ol"
},
{
children: [],
direction: null,
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "Bullet list:",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "first",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 1
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "second",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 2
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "third",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 3
}
],
direction: "ltr",
format: "",
indent: 0,
type: "list",
version: 1,
listType: "bullet",
start: 1,
tag: "ul"
},
{
children: [],
direction: null,
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "Some blockquote??",
type: "text",
version: 1
},
{
type: "linebreak",
version: 1
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "isnt that great?",
type: "text",
version: 1
},
{
type: "linebreak",
version: 1
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "Here comes a blockquote statement",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "quote",
version: 1
},
{
children: [
{
type: "linebreak",
version: 1
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "Left align",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "center align",
type: "text",
version: 1
}
],
direction: "ltr",
format: "center",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "right align",
type: "text",
version: 1
}
],
direction: "ltr",
format: "right",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [],
direction: null,
format: "right",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [],
direction: null,
format: "left",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
format: "",
type: "youtube",
version: 1,
id: "kBUAV4YT1fs",
loop: false,
controls: true,
aspectRatio: "4/3",
autoplay: false,
provider: "youtube"
},
{
children: [
{
altText: "",
caption: {
editorState: {
root: {
children: [],
direction: null,
format: "",
indent: 0,
type: "root",
version: 1
}
}
},
height: 0,
position: "full",
showCaption: false,
src: "https://placehold.co/600x400/png",
type: "inline-image",
version: 1,
width: 0
}
],
direction: null,
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
type: "horizontalrule",
version: 1
},
{
children: [],
direction: null,
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
},
{
children: [
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "This is left column",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
}
],
direction: "ltr",
format: "",
indent: 0,
type: "layout-item",
version: 1
},
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "this is right column",
type: "text",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
}
],
direction: "ltr",
format: "",
indent: 0,
type: "layout-item",
version: 1
}
],
direction: "ltr",
format: "",
indent: 0,
type: "layout-container",
version: 1,
templateColumns: "1fr 1fr"
},
{
children: [],
direction: null,
format: "",
indent: 0,
type: "paragraph",
version: 1,
textFormat: 0
}
],
direction: "ltr",
format: "",
indent: 0,
type: "root",
version: 1
}
} The Lexical editor works as intended, only the renderer doesn't work due to the |
Looking at the source code of const serialize = React.useCallback(
(...)
if (node.type === "block") {
const renderer = blockRenderers[node.fields.blockType] as (
props: unknown
) => React.ReactNode
if (typeof renderer !== "function") {
throw new Error(`Missing block renderer for block type '${node.fields.blockType}'`)
}
return <React.Fragment key={index}>{renderer(node)}</React.Fragment>
}
if (node.type) {
const renderer = blockRenderers[node.type]
if (typeof renderer === "function") {
return (
<React.Fragment key={index}>
{(renderer as Function)({
...node,
...("children" in node && { children: serialize(node.children) })
})}
</React.Fragment>
)
}
}
(...) This way all provided |
I might be wrong, but think this should not be covered by That being said, features like a youtube video could aswell be implemented as a payload block and have a custom renderer within the editor so using them could feel the same way. |
The actual fix here that seems more correct to me would be to allow extending type ElementRenderers and replacing the current |
I am trying out your renderer component with the Lexical playground elements like youtube, image, separator. The serialize callback function throws an error
I think the reason behind is, that there are custom elements which do not have
node.children
set so I would think that the custom block types should be rendered through theblockRenderes
but they are rendered as renderElements. This is how a JSON of Youtube for example looks like:The text was updated successfully, but these errors were encountered: