We are working on a custom PortableText parser in C#, with the possibility to also define some custom parsers for certain HTML elements.
In the example below, the blocks prop contains the output of our parser, but there is a problem, that makes it unrecognizable for @sanity/block-content-to-react. On line 20, our parser would add a marks: [], empty array, that stops the BlockContent rendering with the error:
Cannot read property '_type' of undefined
Removing/commenting out the line fixes the problem. Under the custom image block, we also have a _type: span item which similarily holds an empty marks: [] block, but causes no problem for BlockContent. Why is that?
We are working on a custom PortableText parser in C#, with the possibility to also define some custom parsers for certain HTML elements.
In the example below, the blocks prop contains the output of our parser, but there is a problem, that makes it unrecognizable for
@sanity/block-content-to-react
. On line 20, our parser would add amarks: []
, empty array, that stops theBlockContent
rendering with the error:Removing/commenting out the line fixes the problem. Under the custom image block, we also have a _type: span item which similarily holds an empty
marks: []
block, but causes no problem forBlockContent
. Why is that?https://codesandbox.io/s/young-platform-8kz1i?fontsize=14&hidenavigation=1&theme=light&file=/src/App.js:470-489
The code that fails: https://github.com/sanity-io/block-content-to-hyperscript/blob/d9d5adac36d50c0c012f7bb4099fb6f3fa67b382/src/serializers.js#L24-L26
(Linking to the original Slack conversation with @kmelve https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1600687685152700)