Closed antonbehaeghe closed 6 years ago
I finally understand what this issue is. @antonbehaeghe Please include details on future issues (this goes for any repo, not just this one).
In the Prismic API V2 response, a RichText field contains data like the following:
{
"data": {
"myRichTextField": [
{
"type": "heading1",
"text": "Welcome",
"spans": []
}
]
}
}
spans
can contain data about formatting within the section. If there is no additional formatting, the span array will be empty, such as in the example data above.
Since Gatsby processes this data into a GraphQL API, the empty spans are removed from the Gatsby node. The result looks like the following:
{
"data": {
"myRichTextField": [
{
"type": "heading1",
"text": "Welcome"
}
]
}
}
PrismicDOM.RichText.asHtml
expects a span
property to exist and be an Array as it internally calls Array.prototype.map
on the value. If spans
does not exist, the following error is thrown:
TypeError: Cannot read property 'map' of undefined
I've opened an issue for prismic-richtext
regarding this: https://github.com/prismicio/prismic-richtext/issues/10
Hi @angeloashmore, So it's more like an issue on the Gatsby plugin for prismic I guess. It doesn't feel right to just remove data from the API Response. I don't think that should be fix in the prismic library.
Closing in favor or #24 (providing HTML and text fields as part of the plugin).
Hi @antonbehaeghe, sorry for the late reply. Could you describe the issue?