craft.js
craft.js copied to clipboard
Nested "type" key in Element props leads to serialization error
The following props will cause a "Cannot convert undefined or null to object" error.
<SomeElement foo={{type:"bar"}} />
I suppose the following line causes it: https://github.com/prevwong/craft.js/blob/2b09e3824cfb4f3b660a3f3bb14a14aba108ef34/packages/core/src/utils/serializeNode.tsx#L34
It the type key is nested one level deeper everything works as expected:
<SomeElement foo={{bar:{type:"bar"}}} />
I'm facing this issue too:
We integrating a rich text editor (tiptap) as a Craf.js block. A Tiptap document has a type attribute in every node, causing this issue to raise after any attempt to change the document.
Another case was storing an image, where we had a type attribute for the mime type. We got it working by renaming it to mime.
Any ideas on how to solve it or updates on this issue?
And of course: Thanks for this awesome library!
I just faced the same issue as well. My component accepts a prop with this shape:
mediaSource?: { type: 'token'; token: string } | { type: 'library'; uuid: string };
By changing from type to source the issue went away.
@eduludi did you end up finding a fix for this? Facing the same issue while using tiptap editor.
Why is this function recursively looking for "type" and "children"? I couldn't find a test case that illustrates that point.
Based on my understanding of the data model, it makes no sense to treat these as anything but user data because these represent React node properties when serializing.