From 6bb4cfeef69105a1798d6e1df5276a159799ba3d Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Fri, 12 Nov 2021 11:54:08 +0000 Subject: [PATCH] fix: use forced catchall for preview mode --- demo/pages/previewTest.js | 26 ++++---------------------- src/helpers/config.js | 16 +--------------- test/__snapshots__/index.js.snap | 1 + 3 files changed, 6 insertions(+), 37 deletions(-) diff --git a/demo/pages/previewTest.js b/demo/pages/previewTest.js index d27e2f1198..3f1ea8b98d 100644 --- a/demo/pages/previewTest.js +++ b/demo/pages/previewTest.js @@ -1,21 +1,12 @@ import Link from 'next/link' -const StaticTest = ({ number }) => { +const StaticTest = ({ isPreview }) => { return (
-

- This page uses getStaticProps() and is SSRed when in preview mode. -
-
- By default, it shows the TV show by ID (as static HTML). -
- But when in preview mode, it shows person by ID instead (SSRed). -

-
- -

Number: {number}

+

Is preview? {isPreview ? "Yes!" : "No"}

+

{isPreview ? "Exit Preview" : "Enter Preview"}

Go back home @@ -24,20 +15,11 @@ const StaticTest = ({ number }) => { } export const getStaticProps = async ({ preview }) => { - let number - // In preview mode, use odd number - if (preview) { - number = 3 - } - // In normal mode, use even number - else { - number = 4 - } return { props: { - number, + isPreview: Boolean(preview), }, } } diff --git a/src/helpers/config.js b/src/helpers/config.js index ba1490d9b9..f9246100b0 100644 --- a/src/helpers/config.js +++ b/src/helpers/config.js @@ -80,21 +80,6 @@ exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => { netlifyConfig.redirects.push({ from: `${basePath}/:locale/_next/static/*`, to: `/static/:splat`, status: 200 }) } - const staticManifest = join(netlifyConfig.build.publish, 'static-manifest.json') - if (process.env.EXPERIMENTAL_MOVE_STATIC_PAGES && existsSync(staticManifest)) { - // Static page files need to have a forced redirect for preview mode. Otherwise it's non-forced - const staticFiles = await readJSON(staticManifest) - netlifyConfig.redirects.push( - ...staticFiles.map((file) => ({ - from: `${basePath}/${file}`, - to: HANDLER_FUNCTION_PATH, - status: 200, - force: true, - conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] }, - })), - ) - } - // This is only used in prod, so dev uses `next dev` directly netlifyConfig.redirects.push( { from: `${basePath}/_next/static/*`, to: `/static/:splat`, status: 200 }, @@ -103,6 +88,7 @@ exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => { to: HANDLER_FUNCTION_PATH, status: 200, conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] }, + force: true, }, ...redirects.map((redirect) => ({ from: `${basePath}${redirect}`, diff --git a/test/__snapshots__/index.js.snap b/test/__snapshots__/index.js.snap index 5c693ff14e..6668062021 100644 --- a/test/__snapshots__/index.js.snap +++ b/test/__snapshots__/index.js.snap @@ -212,6 +212,7 @@ Array [ "__next_preview_data", ], }, + "force": true, "from": "/*", "status": 200, "to": "/.netlify/functions/___netlify-handler",