Skip to content

Commit c88a504

Browse files
fix: don't force rewrite in preview mode (#761)
* fix: don't force rewrite in preview mode * chore: update snapshot * fix: remove invalid env var * chore: release 4.0.0-beta.5 Release-as: 4.0.0-beta.5 Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 83378b4 commit c88a504

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/helpers/config.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
const { readJSON } = require('fs-extra')
2+
const { readJSON, existsSync } = require('fs-extra')
33
const { join, dirname, relative } = require('pathe')
44
const slash = require('slash')
55

@@ -79,14 +79,29 @@ exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => {
7979
if (i18n) {
8080
netlifyConfig.redirects.push({ from: `${basePath}/:locale/_next/static/*`, to: `/static/:splat`, status: 200 })
8181
}
82+
83+
const staticManifest = join(netlifyConfig.build.publish, 'static-manifest.json')
84+
if (process.env.EXPERIMENTAL_MOVE_STATIC_PAGES && existsSync(staticManifest)) {
85+
// Static page files need to have a forced redirect for preview mode. Otherwise it's non-forced
86+
const staticFiles = await readJSON(staticManifest)
87+
netlifyConfig.redirects.push(
88+
...staticFiles.map((file) => ({
89+
from: `${basePath}/${file}`,
90+
to: HANDLER_FUNCTION_PATH,
91+
status: 200,
92+
force: true,
93+
conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] },
94+
})),
95+
)
96+
}
97+
8298
// This is only used in prod, so dev uses `next dev` directly
8399
netlifyConfig.redirects.push(
84100
{ from: `${basePath}/_next/static/*`, to: `/static/:splat`, status: 200 },
85101
{
86102
from: `${basePath}/*`,
87103
to: HANDLER_FUNCTION_PATH,
88104
status: 200,
89-
force: true,
90105
conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] },
91106
},
92107
...redirects.map((redirect) => ({

test/__snapshots__/index.js.snap

-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ Array [
156156
"__next_preview_data",
157157
],
158158
},
159-
"force": true,
160159
"from": "/*",
161160
"status": 200,
162161
"to": "/.netlify/functions/___netlify-handler",

0 commit comments

Comments
 (0)