Prismic preview 404 CDN

Hi!

We are encountering an issue lately with the Preview process. It was working well end suddenly stopped working.

The site is not up to date regarding prismic dependencies, we are using prismic-javascript@2.1.4 et prismic-reactjs@1.1.2. We use the deprecated method Prismic.client().previewSession().

On some pages we get an “Internal Server Error” when trying to access a draft preview. Here is the error message we are getting: "Unexpected status code [404] on URL https://repo.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=1&lang=fr-fr&ref={"_tracker"%3A"2KX1knSE"%2C"repo.prismic.io"%3A{“preview”%3A"https%3A%2F%2Frepo.prismic.io%2Fpreviews%2FXx6snBAAAL1uTip_%3AXx7w7hAAAL1uT11r%3FwebsitePreviewId%3DXkLNpxMAAPuqqU0T"}}&q=[[at(document.type%2C%20"menu")]]”

I took the liberty to remove the name of our actual repository and wrote “repo” in its place. The error stacktrace points to the prismic-javascript library.

Did anything change on Prismic’s side?

Thanks for your help.

Hi Jonas,

Welcome to Prismic community, I will try to help you on this.
I’m checking with our dev team if there has been any changes in the codebase that broke the deprecated Prismic.client().previewSession() .

I will let you know once I have some info,

Fares

Hi Fares,

Thank you for your help. I’m looking forward to what you’ll find.

Have a good day.

Regards,
Jonas.

Hi,

I have the same problem.

Everything works properly in development, in production already published content works fine but the preview link for unpublished content ends up in a 404 (with the good preview url though…).

Hi Floran,

It sounds like you haven’t got the preview script enabled in your 404 page as well, it needs this to redirect correctly. We discuss this in the preview troubleshooting document:


Thanks.

Hi !

No, it was correctly included. I’ve just solved it !!

In NextJs, you need to have fallback : true in getStaticPaths or it will always render a 404. It doesn’t happen in development because getStaticPath is rerendered every time !

2 Likes

Awesome, I’ll check if we need to update our docs to include this info.

Glad you found your solution @fcosnier.

We are not using getStaticPaths in our project so I doubt that this solution apply to the problem I mentioned earlier. We use getInitialProps to fetch our data as we’re using next@9.1.6.

Hi Jonas,

We apologized for the delay, in fact, we thought that the issue has been resolved for you, anyway, I will try to help you with this.

In order to debug this issue, I need to have access to the problematic code, so would it be possible to share with me your project code (in a direct message if confidential) as well as the name of the repository you are using.

Looking forward to your reply,
Fares

Hi Fares,

Thanks for your answer. I’ll send you the code by dm and the relevant information too.

Have a good day.
Jonas.

1 Like

Hi,

I've been working with Fares to determine what was the problem at hand here. We narrowed it down to the language slug in the preview URL. Depending on the language we're trying to preview the page in, the previewSession method returns an URL with the language slug as undefined. For example here is the URL for the french language: /fr/destination/gordes-hotel whereas in russian we get /undefined/destination/горд-отель.

I sent Fares all the different document and custom type information. He's going to pass them along to the development team to see what they can find.

1 Like

Hi @j.pauthier I've created an issue in our issue tracker and somebody from the dev team will have a look at it.

Hi @Fares,

In your issue tracker you mean, don't you? Thanks, I'm looking forward to what they'll find.

Yes exactly :sweat_smile:

Hi Jonas,

I've investigated this issue with @amaury from our dev team, and we have noticed that in your project the Russian language locale doesn't exist, and that might explain why you have an undefined in the preview generated URL

I don't know if it is already the case for production or it is only an issue related to dev.

And for the other issue where you had a draft document in fr that gives you 404 when previewing.

This document has never been published as you told me, so we want to see if this is because it's a linked document to another draft (expected behavior) or a real bug of not being able to preview a never published draft document.

Looking forward to your reply,
Fares

Hello Fares,

Yeah indeed, that's my bad. When I debugged with you I forgot that I had another Git branch where I added the work for adding the Russian local. Below can see the diff from that branch:

There are no russian content published to production yet. :slightly_smiling_face:

The french document I sent you previously was linked to a document that was already published and its parent document was also already published when the document was in draft itself. The document got published since our last discussion though.

We tested the behavior you explained above and we were able to reproduce it. Indeed if we create a root document in french (destination_page) we can preview it but if we create a child document this one returns a 404. We found this behavior is not consistent with the documents in russian. If I try to preview a root document in russian I get redirected to a blank page with the error message from our preview page handler. When previewing documents linked to the russian root page or one of their children we get two different behavior, either:

  • We get redirected to a blank page with the same error message as the one from the root document (mainly on details page).
  • We get redirected to a 404 page (mainly on list type document).

I published the updated code for the russian language support in the staging environment if you want to test it. I'll send you more information by private messages.

We have a couple questions:

  1. Is there something we can do to preview documents where their parents or related documents are also in draft? If not, this means we'll need to published broken content because they point to unpublished content so we can preview children content.
  2. Do new languages need specific actions to be published or are they published by default and it's just a matter of whether you published content for these specific languages?

Thanks for your help.

Hi Jonas,

I've continued to investigate with our dev team and here is what we agreed on:

  • there is no specific action to publish a document on a new locale, you just have to select the right one when editing your content.

So for us, the language issue is certainly related to a wrong configuration for the RU language in your project (make a diff with fr).

  • If you want to preview multiple drafts at once, you have to use our Releases feature. It unites the drafts under a single API Ref to be queried

It seems that you're trying to preview the linked document through the parent document.
When going through the eye button, you can only preview one document at a time (meaning the other documents would be the live version of themselves).

I hope that this answers your questions.

Hi Fares,

Thank you for your help. We applied the information you gave us in your answer and we made some progress. We are able to preview some of the russian content.

Here are some fixes we applied:

  • The blank page with the error message was due to express not being able to redirect to the Prismic Preview URL since it had cyrillic characters in it, thus just using encodeURI fixed it.
  • Using Prismic Release feature.

I have a question though, we have some documents that are general and used for all pages (footer, global menu and some commons settings). When we query them from a preview russian page the Prismic API returns undefined even though the documents are available in draft in the russian language and also added to the Release we made. One thing we suspect that could be the culprit is the fact that not all documents linked to the "menu" document for example are translated hence some of these linked documents are still the live french version. Can Prismic return a document that is linked to other documents in a different locale or do they need to all be in the same locale in order to fetch that document?

Thanks again for your time and help.

1 Like

Hi Jonas,

Glad to hear that you have managed to solve those issues, and for the new question you have asked it is that in fact you can't link to a document that is in another locale using content relationship field.
you can fetch it manually thought.

what we recommend is not to use content relationship to use layout (header/footer) but include them as components in your page where you can fetch simultaneously when fetching your page.

Anyway the issue now is related to your codebase as far as I see.

Hope that this answers your question.
Fares

Hi Fares,

The remaining problems were mostly relationships with documents in other locale and missing links. We managed to fix those issues and we now have something showing up in the preview.

I shall close the issue now.

Thanks everyone involved for your help on this issue and especially Fares.

Have an awesome day you all! :grin:

1 Like