Previewing unpublished changes doesn't work

Hi!

I'm trying to configure Prismic previews in a Gatsby project with the gatsby-plugin-prismic-previews.

Previewing published content works well. Also previewing completely new content that is unpublished works well (it will use the 404 page and the HOC withPrismicUnpublishedPreview to resolve this).

The one issue we have is when updating an existing document that is already live and published. Then you will have some draft changes that are unpublished.
When trying to preview that document it will launch the preview and display the original document that is the one that is already live.
How is the plugin suppose to detect that we have some draft changes and display that instead?

It is key to be able to preview changes that you are about to publish. So I assume we are missing something in the configuration.

We use a very simple setup in the gatsby-browser.js.

<PrismicPreviewProvider
    repositoryConfigs={[
      {
        repositoryName: "our_repo_name",
        linkResolver,
        componentResolver: componentResolverFromMap({
          post: PostTemplate,
        }),
      },
    ]}
  >
    {element}
  </PrismicPreviewProvider>

And minimum options in gatsby-config.js.

{
      resolve: "gatsby-plugin-prismic-previews",
      options: {
        repositoryName: "our_repo_name",
        accessToken: "the_access_token",
      },
    },

I mean the integration seems to work well except for the use case I described.

Hello @josefine

Welcome to the Prismic community and thanks for reaching out to us.

Have you also added a _previewable field to the query and declared the withPrismicPreview() function. This setup will automatically detect an active preview session and update the content with the preview data.
Find more details here.

Thanks,
Priyanka

Thank you very much @Priyanka , that is the solution. Not sure how we missed that in the docs :slightly_smiling_face:

You are welcome, @josefine. Feel free to reach out to us if you have any questions.