Adding fields to existing slice error

Hi, this is somewhat related to this issue (Structured Text Error), which still exists and is a pain in the butt.

I have an existing slice within a custom type with a handful of various field types in the repeatable section of the slice. When I added a key text field to this existing slice, one of the Rich Text Fields, which was null by default before, becomes populated with an empty string. However, when I delete the repeatable section and recreate it as it was before, the Rich Text Field remains null.

Why does this happen? This is very frustrating because it messes with frontend validation logic and it makes me nervous about editing custom types, which is the whole point of Prismic!

FYI, I am using Prismic through GraphQL and Gatsby (gatsby-source-prismic-graphql plugin)

Hey Andrey, welcome to the forum!

I'm sorry to hear you're having trouble with your project. Just so you know, we are currently moving away from the gatsby-source-prismic-graphql plugin and starting to use gatsby-source-prismic more now. You can read all about it here: Gatsby-Prismic plugins: what’s going on?

For the time being, we are still giving some support to the one you're using in a fork made to the plugin, so we are encouraging every Prismic + Gatsby user to replace the gatsby-source-prismic-graphql npm package to be @prismicio/gatsby-source-prismic-graphql

But, going back to your case, this is very strange behaviour. Can you show me an example o what the API is retrieving, you can use screenshots.

Hi, Paulina. I am aware of the issues with the gatsby-source-prismic-graphql plugin, but I did not know about the fork. Thank you for letting me know, I will look into that.

This project has two Prismic repos, one staging and one prod. I added the the key text field ipf_field_name to the staging repo, along with populating the label field, and the API call result is below.

    "fields": [
                        {
                          "ipf_field_name": null,
                          "label": "Settlement",
                          "universal_value_reference": "settlement",
                          "value": [
                            {
                              "type": "paragraph",
                              "text": "",
                              "spans": []
                            }
                          ]
                        }
                      ]

The prod repo does not have the ipf_field_name key text field nor do I have the label field populated and the API call result is below.

     "fields": [
                        {
                          "label": null,
                          "universal_value_reference": "settlement",
                          "value": null
                        }
                      ]

As you can see, the value field was null before I added the ipf_field_name key text field to the slice.

Ok I see, you were right, this is related to the thread you linked at the beginning. It's something we are aware of and still have no ETA or clear plans on modifying this. I totally understand that this can become a problem if it makes the front end break.

What you can do is add extra validation to your Rich text fields so that they don't trigger an error, e.g.:

  <RichText  render={ slice.fields.ipf_field_namet || [ ] }  />

Thanks for the tip, Paulina, I'll look into adding that validation. I look forward to having this problem fixed!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.