prismicio / prismic-gatsby

Gatsby plugins for building websites using Prismic
https://prismic.io/docs/technologies/gatsby
Apache License 2.0
313 stars 97 forks source link

No spans field on Rich Text fields #17

Closed antonbehaeghe closed 6 years ago

angeloashmore commented 6 years ago

Hi @antonbehaeghe, sorry for the late reply. Could you describe the issue?

angeloashmore commented 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
angeloashmore commented 6 years ago

I've opened an issue for prismic-richtext regarding this: https://github.com/prismicio/prismic-richtext/issues/10

arnaudlewis commented 6 years ago

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.

angeloashmore commented 6 years ago

Closing in favor or #24 (providing HTML and text fields as part of the plugin).