Prismic behaviour when adding new fields

I just added a new field to a slice and noticed that unless you re-publish at least one document, the field is not available at all in the API response. Once you publish one document, the field appears for all documents using that slice. Is that per design?

The other issue is an issue that has been reported several times before by various people. The default value is simply ignored. I noticed this with Boolean fields before, but it also happens with Select fields.

Here are some scenarios with the current and the expected behaviour - in sequential order:

Scenario Actual Expected
Boolean/Select Field added with default value - no re-publication field not available field available with default value
Re-publication of one document without changing the new field field available, but with value null field available with default value
Re-publication of one document with changing the new field field has selected value field has selected value

As a consequence, even if I might only need the new field on any new document, I either add unnecessary code to verify if the field is even available or I change the new field on all documents forth and back to the defautl value and re-pblish them which however has an undesireable impact in case the last update is used for email circulation or similar use cases.

Is there any good reason why Prismic behaves like this? Is there a simpler, more predictable solution? we already set the rule to check in all cases if a Boolean field is false instead of true to capture the null value.

Hello @peter2

Thanks for posting this question to us.

To answer your first question:

Whenever you make any changes to your documents in Prismic, You always need to re-publish your docs to see new changes. It is designed that way because Prismic API returns only published documents.

This is a known bug, and we are already tracking it in our issue tracker.

Thanks,
Priyanka

Thanks @Priyanka, I believe there is however an inconsistency which is perhaps based on a misunderstanding or a behaviour of the system that is not covered here.

Whenever you make any changes to your documents in Prismic, You always need to re-publish your docs to see new changes. It is designed that way because Prismic API returns only published documents.

If I assume introducing a new field is regarded as a change of a document, than why do all the documents that I have not changed include the field as soon as I re-publish one single document. I think there is a different reason than what you stated. It seems to be more related to the api ref and perhaps that needs to be updated for any slice changes to take effect on all doc's.

In any case, practically speaking, a new field requires code change that affects all pages of the same type. As such the current behaviour that the field appears automatically for all documents (after one get's changed) is very much desirable. The main issue remains that the default value get's ignored for the API result which is indeed quite frustrating as the Prismic UI shows the default value. The authors of the documents are mislead by that. The work-around is also dangerous as the default values are literally hard-coded into the website. So, any change of the default value after the coding achieves is ignored by the frontend.

Hello @peter2

If the Custom Type is repeatable, then the field will appear in all the documents related to it because It's related to Master ref. Whenever you make changes in one doc of a repeatable Custom Type Master ref also changes.

About the default issue of boolean, Select field, we are already tracking it in our issue tracker.

Thanks,
Priyanka