The recommended `/api/exit-preview` is cached on Vercel and only works on the first visit
Closed this issue · 3 comments
Versions
@prismicio/next
: v0.1.3next
: v12.2.4- node: v16.15.0
Reproduction
https://github.com/prismicio-community/nextjs-starter-prismic-blog
Steps to reproduce
Note: When testing, ensure that caching is enabled in the browser (i.e. the "Disable cache" setting is unchecked) and that the DevTools is closed.
- Deploy site to Vercel
- Edit a page and preview on production
- Exit the preview and verify Preview Mode is no longer active
- Start a new preview
- Exit the preview and verify Preview Mode is still active
What is expected?
Previews exit as many times as needed.
What is actually happening?
It only exits the first time. Any subsequent attempt is not exited. However, the Prismic preview token is removed and the request to /api/exit-preview
is successful.
This happens because the endpoint returns a 200 status code. Vercel caches 200 GET requests at the Edge. To prevent the endpoint from being cached, a non-200 status code must be sent, or a non-GET request must be used.
More details are available here: https://vercel.com/docs/concepts/functions/serverless-functions/edge-caching
So you're thinking of a 205 perhaps? Seems like the exact use case 🤔
Yes, exactly. 205 sounds like a good option, better than requiring a POST request.
Fixed as of v0.1.4
. For more details, see: #32.