BUG: preview only works half the time

There appears to be a bug in the prismic backend where mainDocument is NULL (within the request to the token URL) when the preview link is used, e.g.:

 noone@imac20 ~ % curl "https://purecaps.prismic.io/previews/Xw7oLxIAACIApiqf?websitePreviewId=Wi6mSh0AAIJW9KGB"
{"label":"Live now","ref":"Xw7r-hIAACIApjdg","mainDocument":"XwMLlhAAACEAIsdL","type":"LIVE"}
noone@imac20 ~ % 
noone@imac20 ~ % curl "https://purecaps.prismic.io/previews/Xw7r-hIAACIApjdg?websitePreviewId=Wi6mSh0AAIJW9KGB"
{"label":"Live now","ref":"Xw7r-hIAACIApjdg","mainDocument":"XwMLlhAAACEAIsdL","type":"LIVE"}
noone@imac20 ~ % 
noone@imac20 ~ % curl "https://purecaps.prismic.io/previews/Xw7r-hIAACIApjdg?websitePreviewId=Wi6mSh0AAIJW9KGB"
{"label":"Live now","ref":"Xw7r-hIAACIApjdg","mainDocument":null,"type":"LIVE"}
noone@imac20 ~ % 
noone@imac20 ~ % curl "https://purecaps.prismic.io/previews/Xw7r-hIAACIApjdg?websitePreviewId=Wi6mSh0AAIJW9KGB"
{"label":"Live now","ref":"Xw7r-hIAACIApjdg","mainDocument":null,"type":"LIVE"}
noone@imac20 ~ % 
noone@imac20 ~ % curl "https://purecaps.prismic.io/previews/Xw7r-hIAACIApjdg?websitePreviewId=Wi6mSh0AAIJW9KGB"
{"label":"Live now","ref":"Xw7r-hIAACIApjdg","mainDocument":"XwMLlhAAACEAIsdL","type":"LIVE"}


In the php-sdk this line checks if mainDocument isset, otherwise the preview doesn't work.

Please check if this is an error in the prismic backend or php-sdk!
Best regards

Hello Dominik, welcome to the community forum!

In order for me to raise an issue that can be reviewed by the dev team i need a little bit more information:

  1. What would be the expected behaviour?
  2. Which steps need to be taken to reproduce this issue?
  3. Which browser are you using?
  4. Screen-recordings or screenshots to better illustrate the issue would be useful
  5. Version of the Prismic kit that you’re using

Thank you for submitting your case!

Hello Paulina, details here:

  1. seeing the preview of the content
  2. click on the preview link in prismic
  3. not relevant since the URL from the token parameter returns no mainDocument
  4. screen recording is in the gif
  5. not relevant, just check with curl

Best regards

Hi Dominik,

This is an issue that we are aware of, the mainDocument is not reliable and we have chosen to move away from using it which is why we implemented a new preview function in our javascript kit which no longer uses the mainDocument.

I’m going to create an issue in the PHP kit so that we can look in to changing how the preview functionality works there.

If/when we have any updates on this we’ll let you know here.

1 Like

Issue: https://github.com/prismicio/php-kit/issues/169