Skip to content

Commit 6092266

Browse files
committed
chore: fix basePath redirects for fallback preview mode lol pain
1 parent 319d27c commit 6092266

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Diff for: src/lib/helpers/convertToBasePathRedirects.js

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ const convertToBasePathRedirects = ({ basePath, nextRedirects }) => {
3434
},
3535
]
3636
basePathRedirects.push(...indexRedirects)
37+
} else if (r.specialPreviewMode) {
38+
basePathRedirects.push({
39+
route: `${basePath}${r.route}`,
40+
target: r.target,
41+
force: true,
42+
conditions: r.conditions,
43+
})
3744
} else if (!r.route.includes('_next/') && r.target.includes('/.netlify/functions') && r.conditions) {
3845
// If this is a preview mode redirect, we need different behavior than other function targets below
3946
// because the conditions prevent us from doing a route -> basePath/route force

Diff for: src/lib/pages/getStaticPropsWithFallback/redirects.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const getRedirects = async () => {
3030
target: previewModeTarget,
3131
conditions: PREVIEW_MODE_COOKIES,
3232
force: true,
33+
specialPreviewMode: true,
3334
})
3435

3536
// Add one redirect pointing to the ODB

Diff for: src/tests/__snapshots__/basePath.test.js.snap

-4
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,12 @@ exports[`Routing creates Netlify redirects 1`] = `
6666
/foo/getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200
6767
/foo/getServerSideProps/:id /.netlify/functions/next_getServerSideProps_id 200
6868
/foo/getStaticProps/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data
69-
/foo/getStaticProps/withFallback/:id /getStaticProps/withFallback/[id] 200
7069
/foo/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
7170
/foo/getStaticProps/withFallback/:slug/* /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
72-
/foo/getStaticProps/withFallback/:slug/* /getStaticProps/withFallback/[...slug] 200
7371
/foo/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
7472
/foo/getStaticProps/withFallbackBlocking/:id /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
75-
/foo/getStaticProps/withFallbackBlocking/:id /getStaticProps/withFallbackBlocking/[id] 200
7673
/foo/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
7774
/foo/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data
78-
/foo/getStaticProps/withRevalidate/withFallback/:id /getStaticProps/withRevalidate/withFallback/[id] 200
7975
/foo/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
8076
/foo/shows/:id /.netlify/functions/next_shows_id 200
8177
/foo/shows/:params/* /.netlify/functions/next_shows_params 200

0 commit comments

Comments
 (0)