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!
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:
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.
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!
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.
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.
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.