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

fix: resolve an issue where previews would not show if the default URL led to a 404 page #51

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Types of changes

Description

This PR fixes a bug where preview content would not appear when using a shared preview link.

If @prismicio/next's redirectToPreviewURL() defaultURL option pointed to a page that doesn't exist (i.e. a 404 status code), the page would not be refreshed. This happens because <PrismicPreview> checked for res.ok when fetching the /api/preview endpoint.

Rather than check for res.ok, which may result in a 404 despite properly updating preview data, <PrismicPreview> now checks that res.redirected is true.

Checklist:

🐳

github-actions[bot] commented 2 years ago

size-limit report 📦

Path Size
./dist/index.cjs 5.96 KB (+0.09% 🔺)
./dist/index.js 2.74 KB (+0.22% 🔺)