prismicio / prismic-next

Helpers to integrate Prismic into Next.js apps
https://prismic.io/docs/technologies/nextjs
Apache License 2.0
56 stars 7 forks source link

exitPreview() is not working #45

Closed kb1995 closed 2 years ago

kb1995 commented 2 years ago

Packages version:

"@prismicio/client": "^6.7.1",
    "@prismicio/helpers": "^2.3.5",
    "@prismicio/next": "^0.1.5",
    "@prismicio/react": "^2.4.4",

api/exit-preview.js is as follows:

import { exitPreview } from "@prismicio/next"

export default async function exit(req, res) {
  await exitPreview({ res, req })
}

Steps to reproduce:

github-actions[bot] commented 2 years ago

This issue has been labeled as a bug since it was created using the 🚨 Bug Report Template.

Hi there, thank you so much for the report!

Following our Maintenance Process, we will review your bug report and get back to you next Wednesday. To ensure a smooth review of your issue and avoid unnecessary delays, please make sure your issue includes the following:

If you have identified the cause of the bug described in your report and know how to fix it, you're more than welcome to open a pull request address it. Check out our quick start guide for a simple contribution process.

If you think your issue is a question (not a bug) and would like quicker support, please close this issue and forward it to an appropriate section on our community forum: https://community.prismic.io

- The Prismic Open-Source Team

angeloashmore commented 2 years ago

Hey @kb1995, I was away on vacation but I'm back now. 🙂

There was a bug in @prismicio/next that caused this exact issue when deploying to CDNs that aggressively cache API route responses, including Vercel. This is fixed as of v0.1.4 where exitPreview() now returns a 205 status code.

For more details on the issue and the fix, see #32.

I see you're using at least v0.1.5, which already includes the fix, so you may have a cached response stored in your browser. Could you clear your browser cache (specifically for the /api/exit-preview route) and try again? You should see a 205 status code on the /api/exit-preview route, not a 200.

Please let me know if this fixes the issue. Thanks!

angeloashmore commented 2 years ago

I'm going to close this issue as it has become stale, but feel free to reply here. We can continue the discussion and re-open if necessary. Thanks! 🙂

grahamd711 commented 4 weeks ago

hi @angeloashmore we get a 500 error when calling exitPreview using draftMode().disable().

Steps to recreate:

  1. Preview an unpublished document
  2. Close the Prismic toolbar
  3. Next.js App shows 500 error

Is this expected behavior? it seems it is based on the code.

`if (config?.res) { // Assume Preview Mode is being used.

    config.res.clearPreviewData();

    // `Cache-Control` header is used to prevent CDN-level caching.
    config.res.setHeader("Cache-Control", "no-store");

    config.res.json({ success: true });

    return;
} else {
    // Assume Draft Mode is being used.

    draftMode().disable();

    // `Cache-Control` header is used to prevent CDN-level caching.
    return new Response(JSON.stringify({ success: true }), {
        headers: {
            "Cache-Control": "no-store",
        },
    });
}`

Screenshot 2024-09-23 at 10 32 01 AM

This only happens on unpublished drafts, but is there any way to improve this experience? maybe redirect content editor to homepage?