prismicio / prismic-next

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

The recommended `/api/exit-preview` is cached on Vercel and only works on the first visit #31

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Versions

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.

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

lihbr commented 2 years ago

So you're thinking of a 205 perhaps? Seems like the exact use case πŸ€”

angeloashmore commented 2 years ago

Yes, exactly. 205 sounds like a good option, better than requiring a POST request.

angeloashmore commented 2 years ago

Fixed as of v0.1.4. For more details, see: #32.