Structured Text Error

If you add text inside of a Structured Text field, save the document, then delete all of the text within that field, and save again, there seems to be an empty paragraph and break tag left over?

This is causing some annoying issues on the front end, as now I need to check for the field being empty OR the field containing these empty tags e.g. empty.

Not the end of the world by any means, but would love to know if there was a way to fix it!

1 Like

Hey Tim,

Sorry I missed this.

Can you tell what development kit your are using and what is being returned in your api response after you delete the text?

Thanks.

Hey Phil,

Thanks for following up!

I’m using graphql, and the results are below from the Prismic GraphiQL interface.

So you can replicate, all you need to do is make a new custom type with a Rich Text Field, that supports paragraphs (and multiple paragraphs), e.g. the default type of rich text.

Then if you follow the 3 steps below, you will see how the empty paragraph tag and line break is orphaned in the field, which is still sent to the output.

Step 1) Create new document, save and publish. Do not add any data to the fields. View in GraphiQL:

{
  "data": {
    "article": {
      "footnote": null,
    }
  }
}

Step 2) Enter some content into the field, save and publish. View in GraphiQL:

{
  "data": {
    "article": {
      "footnote": [
        {
          "type": "paragraph",
          "text": "test",
          "spans": []
        }
      ],
    }
  }
}

Step 3) Deleting the content from the field (e.g. completely empty field), save and publish. View in GraphiQL:

{
  "data": {
    "article": {
      "footnote": [
        {
          "type": "paragraph",
          "text": "",
          "spans": []
        }
      ],
    }
  }
}

OK, got you now.

We are aware of this. I believe this was a choice from the team, I can’t remember exactly the reasoning, so I’m going to contact them for extra information on this. Once I know more I’ll update you here.

Thanks @Phil,

I’ll be interested to hear what the team says, or has in store for this.

Might be handy for others to know as well, because I was scratching my head for a while there.
I was obviously expecting a null response but couldn’t figure out why I was getting an empty paragraph.

So on the front end you must check for null as well as an empty paragraph string within the results array/object, if you don’t want extra spaces!

Cheers,

So I talked with some of the team and there doesn’t appear to be structural reason why returning the data like this is necessary and the team will now begin making plans to fix this.

I don’t have an ETA of when/if they will do this, but as soon as they have more information or have anymore questions, they will get update you here.

Thanks.

1 Like

This is being tracked as an open feature request.

If you have another use-case for this feature, you can 'Flag' this topic to reopen. Please use the :heart: button to show your support for the feature and check out our Feature Request Guidelines.

Hi @Phil . I'm having a similar issue. While the field is empty in the Documents interface the API response contains an empty p tag.
This is quite troublesome because we have conditional display based on the fact that the field has any data inserted or not.

Current situation:

"additional_information": [
        {
            "type": "paragraph",
            "text": "",
            "spans": []
        }
    ],

while I would expect

 "additional_information": [],

Do you have any details on how can we avoid having this kind of situation? Thanks!

Hello @dan.nistor

This is something we are aware of and still have no ETA or clear plans on modifying this. I understand that this is troublesome.

You need to apply conditional validation to the Rich Text fields so that they don't throw an error if it's empty.

Thanks,
Priyanka

Hello @dan.nistor

I have got some information from my colleague. What version of @prismic/helpers are you using? Prismic helpers has this functionality to check if a field has a value.
Find more detail in the@prismic/helpers technical reference article.

Let me know if you have further questions.

Thanks,
Priyanka

Hi @Priyanka, thanks for the quick response.
Unfortunately the @prismic/helpers cannot be used in my case because I'm using REST API and the php sdk.

@dan.nistor In that case you need to apply conditional validation to the Rich Text fields so that they don't throw an error if it's empty.

Feel free to reach out to us if you have any questions.

Thanks,
Priyanka

It's nice to hear that the prismic team just ignore basic issues like this...

Hey @Phil,

We're approaching the 2 year anniversary of this post now and I was wondering how your talk went with the team?

They were meant to update us here but ..... crickets lol.

Cheers,
Tim

Hello Tim,

I apologies but there is no update.

Thanks,
Priyanka