promedico
(Dominik Fuchshofer)
July 15, 2020, 12:08pm
1
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"}
*/
public function previewSession(string $token, LinkResolver $linkResolver, string $defaultUrl) : string
{
try {
$response = $this->getHttpClient()->request('GET', $token);
} catch (GuzzleException $guzzleException) {
throw Exception\RequestFailureException::fromGuzzleException($guzzleException);
}
/** @var \Psr\Http\Message\ResponseInterface $response */
$response = \json_decode((string) $response->getBody());
if (isset($response->mainDocument)) {
$documents = $this
->query(Predicates::at("document.id", $response->mainDocument), ['ref' => $token, 'lang' => '*'])
->results;
if (count($documents) > 0) {
if ($url = $linkResolver($documents[0])) {
return $url;
}
}
}
return $defaultUrl;
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
Pau
July 15, 2020, 7:44pm
2
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:
What would be the expected behaviour?
Which steps need to be taken to reproduce this issue?
Which browser are you using?
Screen-recordings or screenshots to better illustrate the issue would be useful
Version of the Prismic kit that you’re using
Thank you for submitting your case!
promedico
(Dominik Fuchshofer)
July 16, 2020, 6:15am
3
Hello Paulina, details here:
seeing the preview of the content
click on the preview link in prismic
not relevant since the URL from the token parameter returns no mainDocument
screen recording is in the gif
not relevant, just check with curl
Best regards
Phil
(Phil Snow)
July 16, 2020, 11:29am
4
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.
Pau
closed , flag & select 'Something Else' to reopen.
September 25, 2020, 7:57pm
9
This thread is being monitored as an open ticket in the internal Prismic issue tracker. The Prismic support team will update this post as we get more information from our dev team. If you have a similar use-case, you can ‘Flag’ this topic to reopen and add it here.