From 2a7bdb5af8dd173b7351698b37af7c6066be978c Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Thu, 29 Jul 2021 04:27:58 -0400 Subject: [PATCH 1/6] fix: preview mode for odb/fallback pages --- .../helpers/setupNetlifyFunctionForPage.js | 7 +++--- src/lib/pages/getStaticProps/redirects.js | 9 +++++-- .../pages/getStaticPropsWithFallback/setup.js | 11 ++++++--- src/lib/templates/getTemplate.js | 4 ++-- src/tests/__snapshots__/basePath.test.js.snap | 24 +++++++++---------- src/tests/__snapshots__/defaults.test.js.snap | 24 +++++++++---------- src/tests/__snapshots__/i18n.test.js.snap | 24 +++++++++---------- 7 files changed, 57 insertions(+), 46 deletions(-) diff --git a/src/lib/helpers/setupNetlifyFunctionForPage.js b/src/lib/helpers/setupNetlifyFunctionForPage.js index 273c66547f..cb398dc8ca 100644 --- a/src/lib/helpers/setupNetlifyFunctionForPage.js +++ b/src/lib/helpers/setupNetlifyFunctionForPage.js @@ -11,7 +11,7 @@ const getNextDistDir = require('./getNextDistDir') const { logItem } = require('./logger') // Create a Netlify Function for the page with the given file path -const setupNetlifyFunctionForPage = async ({ filePath, functionsPath, isApiPage, isISR }) => { +const setupNetlifyFunctionForPage = async ({ filePath, functionsPath, isApiPage, isODB, forFallbackPreviewMode }) => { // Set function name based on file path const functionName = getNetlifyFunctionName(filePath, isApiPage) const functionDirectory = join(functionsPath, functionName) @@ -23,8 +23,9 @@ const setupNetlifyFunctionForPage = async ({ filePath, functionsPath, isApiPage, } // Write entry point to function directory - const entryPointPath = join(functionDirectory, `${functionName}.js`) - await writeFile(entryPointPath, getTemplate({ filePath, isISR })) + const fileName = forFallbackPreviewMode ? `preview-${functionName}` : functionName + const entryPointPath = join(functionDirectory, `${fileName}.js`) + await writeFile(entryPointPath, getTemplate({ filePath, isODB })) // Copy function helper await copy(join(TEMPLATES_DIR, 'getHandlerFunction.js'), join(functionDirectory, 'getHandlerFunction.js')) diff --git a/src/lib/pages/getStaticProps/redirects.js b/src/lib/pages/getStaticProps/redirects.js index 44a22b587e..1e4ea41445 100644 --- a/src/lib/pages/getStaticProps/redirects.js +++ b/src/lib/pages/getStaticProps/redirects.js @@ -6,6 +6,7 @@ const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect const asyncForEach = require('../../helpers/asyncForEach') const getFilePathForRoute = require('../../helpers/getFilePathForRoute') const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName') +const isRouteWithFallback = require('../../helpers/isRouteWithFallback') const getPages = require('./pages') @@ -35,11 +36,15 @@ const getRedirects = async () => { const relativePath = getFilePathForRoute(srcRoute || route, 'js') const filePath = slash(join('pages', relativePath)) const functionName = getNetlifyFunctionName(filePath) + const isODB = await isRouteWithFallback(srcRoute) // Preview mode conditions const conditions = ['Cookie=__prerender_bypass,__next_preview_data'] + // ODB pages' preview mode needs a special flagged standard function because + // their default function (an ODB) is not functional for preview mode const target = `/.netlify/functions/${functionName}` - const previewModeRedirect = { conditions, force: true, target } + const previewModeTarget = isODB ? `/.netlify/functions/preview-${functionName}` : target + const previewModeRedirect = { conditions, force: true, target: previewModeTarget } // Add a preview mode redirect for the standard route redirects.push({ @@ -54,7 +59,7 @@ const getRedirects = async () => { }) // Preview mode default locale redirect must precede normal default locale redirect - await addDefaultLocaleRedirect(redirects, route, target, previewModeRedirect) + await addDefaultLocaleRedirect(redirects, route, target, { conditions, force: true }) await addDefaultLocaleRedirect(redirects, route) }) diff --git a/src/lib/pages/getStaticPropsWithFallback/setup.js b/src/lib/pages/getStaticPropsWithFallback/setup.js index 0346c08e7d..dd755041f7 100644 --- a/src/lib/pages/getStaticPropsWithFallback/setup.js +++ b/src/lib/pages/getStaticPropsWithFallback/setup.js @@ -14,11 +14,16 @@ const setup = async (functionsPath) => { const pages = await getPages() // Create Netlify Function for every page - return pages.map(({ route }) => { + return pages.reduce((jobs, { route }) => { const relativePath = getFilePathForRoute(route, 'js') const filePath = slash(join('pages', relativePath)) - return { type: 'function', filePath, functionsPath, isISR: true } - }) + // Need two different functions - one ODB for normal pages, one standard for preview mode + return [ + ...jobs, + { type: 'function', filePath, functionsPath, isODB: true }, + { type: 'function', filePath, functionsPath, forFallbackPreviewMode: true }, + ] + }, []) } module.exports = setup diff --git a/src/lib/templates/getTemplate.js b/src/lib/templates/getTemplate.js index c7b5ddd1d2..365baaa86c 100644 --- a/src/lib/templates/getTemplate.js +++ b/src/lib/templates/getTemplate.js @@ -1,5 +1,5 @@ -const getTemplate = ({ filePath, isISR }) => { - if (isISR) { +const getTemplate = ({ filePath, isODB }) => { + if (isODB) { return `// Auto-generated file. DO NOT MODIFY. const { getHandlerFunction } = require('./getHandlerFunction') const { builder } = require('@netlify/functions') diff --git a/src/tests/__snapshots__/basePath.test.js.snap b/src/tests/__snapshots__/basePath.test.js.snap index ee4b58d4a6..96fc1b7b6d 100644 --- a/src/tests/__snapshots__/basePath.test.js.snap +++ b/src/tests/__snapshots__/basePath.test.js.snap @@ -8,12 +8,12 @@ exports[`Routing creates Netlify redirects 1`] = ` /_next/data/%BUILD_ID%/getStaticProps/2.json /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getStaticProps/static.json /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getStaticProps/with-revalidate.json /.netlify/functions/next_getStaticProps_withrevalidate 200 -/_next/data/%BUILD_ID%/getStaticProps/withFallback/3.json /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallback/4.json /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/1.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/2.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallback/3.json /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallback/4.json /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/1.json /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/2.json /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /_next/data/%BUILD_ID%/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /api/hello-background /foo/api/hello-background 301! @@ -31,17 +31,17 @@ exports[`Routing creates Netlify redirects 1`] = ` /foo/getStaticProps/static /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data /foo/getStaticProps/static /getStaticProps/static 200 /foo/getStaticProps/with-revalidate /.netlify/functions/next_getStaticProps_withrevalidate 200 -/foo/getStaticProps/withFallback/3 /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallback/3 /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /foo/getStaticProps/withFallback/3 /getStaticProps/withFallback/3 200 -/foo/getStaticProps/withFallback/4 /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallback/4 /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /foo/getStaticProps/withFallback/4 /getStaticProps/withFallback/4 200 -/foo/getStaticProps/withFallback/my/path/1 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallback/my/path/1 /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data /foo/getStaticProps/withFallback/my/path/1 /getStaticProps/withFallback/my/path/1 200 -/foo/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallback/my/path/2 /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data /foo/getStaticProps/withFallback/my/path/2 /getStaticProps/withFallback/my/path/2 200 -/foo/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallbackBlocking/3 /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /foo/getStaticProps/withFallbackBlocking/3 /getStaticProps/withFallbackBlocking/3 200 -/foo/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallbackBlocking/4 /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /foo/getStaticProps/withFallbackBlocking/4 /getStaticProps/withFallbackBlocking/4 200 /foo/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /foo/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 diff --git a/src/tests/__snapshots__/defaults.test.js.snap b/src/tests/__snapshots__/defaults.test.js.snap index 8505534f71..d547194a4b 100644 --- a/src/tests/__snapshots__/defaults.test.js.snap +++ b/src/tests/__snapshots__/defaults.test.js.snap @@ -16,12 +16,12 @@ exports[`Routing creates Netlify redirects 1`] = ` /_next/data/%BUILD_ID%/getStaticProps/2.json /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getStaticProps/static.json /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getStaticProps/with-revalidate.json /.netlify/functions/next_getStaticProps_withrevalidate 200 -/_next/data/%BUILD_ID%/getStaticProps/withFallback/3.json /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallback/4.json /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/1.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/2.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallback/3.json /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallback/4.json /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/1.json /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/2.json /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /_next/data/%BUILD_ID%/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /api/hello-background /.netlify/functions/next_api_hello-background 200 @@ -31,12 +31,12 @@ exports[`Routing creates Netlify redirects 1`] = ` /getStaticProps/2 /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/static /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/with-revalidate /.netlify/functions/next_getStaticProps_withrevalidate 200 -/getStaticProps/withFallback/3 /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/getStaticProps/withFallback/4 /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/getStaticProps/withFallback/my/path/1 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data -/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withFallback/3 /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withFallback/4 /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withFallback/my/path/1 /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withFallback/my/path/2 /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withFallbackBlocking/3 /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withFallbackBlocking/4 /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /_next/data/%BUILD_ID%/getServerSideProps/all.json /.netlify/functions/next_getServerSideProps_all_slug 200 diff --git a/src/tests/__snapshots__/i18n.test.js.snap b/src/tests/__snapshots__/i18n.test.js.snap index 092d2653c6..831997d575 100644 --- a/src/tests/__snapshots__/i18n.test.js.snap +++ b/src/tests/__snapshots__/i18n.test.js.snap @@ -11,12 +11,12 @@ exports[`Routing creates Netlify redirects 1`] = ` /_next/data/%BUILD_ID%/en/getStaticProps/2.json /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/en/getStaticProps/static.json /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/en/getStaticProps/with-revalidate.json /.netlify/functions/next_getStaticProps_withrevalidate 200 -/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/3.json /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/4.json /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/my/path/1.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/my/path/2.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data -/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/3.json /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/4.json /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/my/path/1.json /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/my/path/2.json /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /_next/data/%BUILD_ID%/es.json /.netlify/functions/next_index 200 @@ -32,12 +32,12 @@ exports[`Routing creates Netlify redirects 1`] = ` /en/getStaticProps/2 /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data /en/getStaticProps/static /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data /en/getStaticProps/with-revalidate /.netlify/functions/next_getStaticProps_withrevalidate 200 -/en/getStaticProps/withFallback/3 /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/en/getStaticProps/withFallback/4 /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/en/getStaticProps/withFallback/my/path/1 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/en/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/en/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data -/en/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/en/getStaticProps/withFallback/3 /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/en/getStaticProps/withFallback/4 /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/en/getStaticProps/withFallback/my/path/1 /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/en/getStaticProps/withFallback/my/path/2 /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/en/getStaticProps/withFallbackBlocking/3 /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/en/getStaticProps/withFallbackBlocking/4 /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /en/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /en/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /es /.netlify/functions/next_index 200 From 319d27cebfda080b2e3b0200c9b5420e07b08064 Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Thu, 29 Jul 2021 10:11:47 -0400 Subject: [PATCH 2/6] chore: add new preview redirect to standard function for fallback srcRoutes --- src/lib/config.js | 3 +++ src/lib/helpers/getPreviewModeFunctionName.js | 5 +++++ src/lib/helpers/setupNetlifyFunctionForPage.js | 3 ++- src/lib/pages/getStaticProps/redirects.js | 3 ++- .../pages/getStaticPropsWithFallback/redirects.js | 13 ++++++++++++- src/tests/__snapshots__/basePath.test.js.snap | 8 ++++++++ src/tests/__snapshots__/defaults.test.js.snap | 4 ++++ src/tests/__snapshots__/i18n.test.js.snap | 4 ++++ 8 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/lib/helpers/getPreviewModeFunctionName.js diff --git a/src/lib/config.js b/src/lib/config.js index 5b14bb7388..262f015308 100644 --- a/src/lib/config.js +++ b/src/lib/config.js @@ -38,6 +38,8 @@ const CUSTOM_HEADERS_PATH = join('.', '_headers') // creating the next/image redirect const NEXT_IMAGE_FUNCTION_NAME = 'next_image' +const PREVIEW_MODE_COOKIES = ['Cookie=__prerender_bypass,__next_preview_data'] + const SRC_FILES = [PUBLIC_PATH, NEXT_CONFIG_PATH, CUSTOM_REDIRECTS_PATH, CUSTOM_HEADERS_PATH, ...NEXT_SRC_DIRS] module.exports = { @@ -52,4 +54,5 @@ module.exports = { CUSTOM_HEADERS_PATH, NEXT_IMAGE_FUNCTION_NAME, SRC_FILES, + PREVIEW_MODE_COOKIES, } diff --git a/src/lib/helpers/getPreviewModeFunctionName.js b/src/lib/helpers/getPreviewModeFunctionName.js new file mode 100644 index 0000000000..ea08080bf8 --- /dev/null +++ b/src/lib/helpers/getPreviewModeFunctionName.js @@ -0,0 +1,5 @@ +// Some pages (getStaticProps/withFallback) require a separate standard function for preview mode; this provides the name for that function, to be called in several places + +const getPreviewModeFunctionName = (functionName) => `preview-${functionName}` + +module.exports = getPreviewModeFunctionName diff --git a/src/lib/helpers/setupNetlifyFunctionForPage.js b/src/lib/helpers/setupNetlifyFunctionForPage.js index cb398dc8ca..3102f74e3e 100644 --- a/src/lib/helpers/setupNetlifyFunctionForPage.js +++ b/src/lib/helpers/setupNetlifyFunctionForPage.js @@ -8,6 +8,7 @@ const getTemplate = require('../templates/getTemplate') const copyDynamicImportChunks = require('./copyDynamicImportChunks') const getNetlifyFunctionName = require('./getNetlifyFunctionName') const getNextDistDir = require('./getNextDistDir') +const getPreviewModeFunctionName = require('./getPreviewModeFunctionName') const { logItem } = require('./logger') // Create a Netlify Function for the page with the given file path @@ -23,7 +24,7 @@ const setupNetlifyFunctionForPage = async ({ filePath, functionsPath, isApiPage, } // Write entry point to function directory - const fileName = forFallbackPreviewMode ? `preview-${functionName}` : functionName + const fileName = forFallbackPreviewMode ? getPreviewModeFunctionName(functionName) : functionName const entryPointPath = join(functionDirectory, `${fileName}.js`) await writeFile(entryPointPath, getTemplate({ filePath, isODB })) diff --git a/src/lib/pages/getStaticProps/redirects.js b/src/lib/pages/getStaticProps/redirects.js index 1e4ea41445..6ca0361c5a 100644 --- a/src/lib/pages/getStaticProps/redirects.js +++ b/src/lib/pages/getStaticProps/redirects.js @@ -6,6 +6,7 @@ const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect const asyncForEach = require('../../helpers/asyncForEach') const getFilePathForRoute = require('../../helpers/getFilePathForRoute') const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName') +const getPreviewModeFunctionName = require('../../helpers/getPreviewModeFunctionName') const isRouteWithFallback = require('../../helpers/isRouteWithFallback') const getPages = require('./pages') @@ -43,7 +44,7 @@ const getRedirects = async () => { // ODB pages' preview mode needs a special flagged standard function because // their default function (an ODB) is not functional for preview mode const target = `/.netlify/functions/${functionName}` - const previewModeTarget = isODB ? `/.netlify/functions/preview-${functionName}` : target + const previewModeTarget = isODB ? `/.netlify/functions/${getPreviewModeFunctionName(functionName)}` : target const previewModeRedirect = { conditions, force: true, target: previewModeTarget } // Add a preview mode redirect for the standard route diff --git a/src/lib/pages/getStaticPropsWithFallback/redirects.js b/src/lib/pages/getStaticPropsWithFallback/redirects.js index 51b2e6b918..62b2e1aa7c 100644 --- a/src/lib/pages/getStaticPropsWithFallback/redirects.js +++ b/src/lib/pages/getStaticPropsWithFallback/redirects.js @@ -2,10 +2,12 @@ const { join } = require('path') const slash = require('slash') +const { PREVIEW_MODE_COOKIES } = require('../../config') const addLocaleRedirects = require('../../helpers/addLocaleRedirects') const asyncForEach = require('../../helpers/asyncForEach') const getFilePathForRoute = require('../../helpers/getFilePathForRoute') const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName') +const getPreviewModeFunctionName = require('../../helpers/getPreviewModeFunctionName') const getPages = require('./pages') @@ -18,10 +20,19 @@ const getRedirects = async () => { const filePath = slash(join('pages', relativePath)) const functionName = getNetlifyFunctionName(filePath) const target = `/.netlify/functions/${functionName}` + const previewModeTarget = `/.netlify/functions/${getPreviewModeFunctionName(functionName)}` await addLocaleRedirects(redirects, route, target) - // Add one redirect for the page + // Add a redirect for preview mode pointing to the standard function + redirects.push({ + route, + target: previewModeTarget, + conditions: PREVIEW_MODE_COOKIES, + force: true, + }) + + // Add one redirect pointing to the ODB redirects.push({ route, target, diff --git a/src/tests/__snapshots__/basePath.test.js.snap b/src/tests/__snapshots__/basePath.test.js.snap index 96fc1b7b6d..f7cc332775 100644 --- a/src/tests/__snapshots__/basePath.test.js.snap +++ b/src/tests/__snapshots__/basePath.test.js.snap @@ -65,9 +65,17 @@ exports[`Routing creates Netlify redirects 1`] = ` /foo/getServerSideProps/all /.netlify/functions/next_getServerSideProps_all_slug 200 /foo/getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200 /foo/getServerSideProps/:id /.netlify/functions/next_getServerSideProps_id 200 +/foo/getStaticProps/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallback/:id /getStaticProps/withFallback/[id] 200 /foo/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200 +/foo/getStaticProps/withFallback/:slug/* /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallback/:slug/* /getStaticProps/withFallback/[...slug] 200 /foo/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200 +/foo/getStaticProps/withFallbackBlocking/:id /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withFallbackBlocking/:id /getStaticProps/withFallbackBlocking/[id] 200 /foo/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200 +/foo/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withRevalidate/withFallback/:id /getStaticProps/withRevalidate/withFallback/[id] 200 /foo/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200 /foo/shows/:id /.netlify/functions/next_shows_id 200 /foo/shows/:params/* /.netlify/functions/next_shows_params 200 diff --git a/src/tests/__snapshots__/defaults.test.js.snap b/src/tests/__snapshots__/defaults.test.js.snap index d547194a4b..5dcb78ae85 100644 --- a/src/tests/__snapshots__/defaults.test.js.snap +++ b/src/tests/__snapshots__/defaults.test.js.snap @@ -52,9 +52,13 @@ exports[`Routing creates Netlify redirects 1`] = ` /getServerSideProps/all /.netlify/functions/next_getServerSideProps_all_slug 200 /getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200 /getServerSideProps/:id /.netlify/functions/next_getServerSideProps_id 200 +/getStaticProps/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200 +/getStaticProps/withFallback/:slug/* /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200 +/getStaticProps/withFallbackBlocking/:id /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200 +/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200 /nextimg/* /.netlify/functions/next_image 200 /shows/:id /.netlify/functions/next_shows_id 200 diff --git a/src/tests/__snapshots__/i18n.test.js.snap b/src/tests/__snapshots__/i18n.test.js.snap index 831997d575..fab2b12134 100644 --- a/src/tests/__snapshots__/i18n.test.js.snap +++ b/src/tests/__snapshots__/i18n.test.js.snap @@ -118,9 +118,13 @@ exports[`Routing creates Netlify redirects 1`] = ` /getServerSideProps/all /.netlify/functions/next_getServerSideProps_all_slug 200 /getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200 /getServerSideProps/:id /.netlify/functions/next_getServerSideProps_id 200 +/getStaticProps/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200 +/getStaticProps/withFallback/:slug/* /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200 +/getStaticProps/withFallbackBlocking/:id /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200 +/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200 /nextimg/* /.netlify/functions/next_image 200 /shows/:id /.netlify/functions/next_shows_id 200 From 6092266c335c47a34b536fd7dc933f282515b3fb Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Thu, 29 Jul 2021 10:32:23 -0400 Subject: [PATCH 3/6] chore: fix basePath redirects for fallback preview mode lol pain --- src/lib/helpers/convertToBasePathRedirects.js | 7 +++++++ src/lib/pages/getStaticPropsWithFallback/redirects.js | 1 + src/tests/__snapshots__/basePath.test.js.snap | 4 ---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/helpers/convertToBasePathRedirects.js b/src/lib/helpers/convertToBasePathRedirects.js index f7d380228d..326f530214 100644 --- a/src/lib/helpers/convertToBasePathRedirects.js +++ b/src/lib/helpers/convertToBasePathRedirects.js @@ -34,6 +34,13 @@ const convertToBasePathRedirects = ({ basePath, nextRedirects }) => { }, ] basePathRedirects.push(...indexRedirects) + } else if (r.specialPreviewMode) { + basePathRedirects.push({ + route: `${basePath}${r.route}`, + target: r.target, + force: true, + conditions: r.conditions, + }) } else if (!r.route.includes('_next/') && r.target.includes('/.netlify/functions') && r.conditions) { // If this is a preview mode redirect, we need different behavior than other function targets below // because the conditions prevent us from doing a route -> basePath/route force diff --git a/src/lib/pages/getStaticPropsWithFallback/redirects.js b/src/lib/pages/getStaticPropsWithFallback/redirects.js index 62b2e1aa7c..1c3263c312 100644 --- a/src/lib/pages/getStaticPropsWithFallback/redirects.js +++ b/src/lib/pages/getStaticPropsWithFallback/redirects.js @@ -30,6 +30,7 @@ const getRedirects = async () => { target: previewModeTarget, conditions: PREVIEW_MODE_COOKIES, force: true, + specialPreviewMode: true, }) // Add one redirect pointing to the ODB diff --git a/src/tests/__snapshots__/basePath.test.js.snap b/src/tests/__snapshots__/basePath.test.js.snap index f7cc332775..f7dfae214d 100644 --- a/src/tests/__snapshots__/basePath.test.js.snap +++ b/src/tests/__snapshots__/basePath.test.js.snap @@ -66,16 +66,12 @@ exports[`Routing creates Netlify redirects 1`] = ` /foo/getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200 /foo/getServerSideProps/:id /.netlify/functions/next_getServerSideProps_id 200 /foo/getStaticProps/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/foo/getStaticProps/withFallback/:id /getStaticProps/withFallback/[id] 200 /foo/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200 /foo/getStaticProps/withFallback/:slug/* /.netlify/functions/preview-next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data -/foo/getStaticProps/withFallback/:slug/* /getStaticProps/withFallback/[...slug] 200 /foo/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200 /foo/getStaticProps/withFallbackBlocking/:id /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data -/foo/getStaticProps/withFallbackBlocking/:id /getStaticProps/withFallbackBlocking/[id] 200 /foo/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200 /foo/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data -/foo/getStaticProps/withRevalidate/withFallback/:id /getStaticProps/withRevalidate/withFallback/[id] 200 /foo/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200 /foo/shows/:id /.netlify/functions/next_shows_id 200 /foo/shows/:params/* /.netlify/functions/next_shows_params 200 From 83ecca8ff451e84b566e685cca28b1679f7856a9 Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Thu, 29 Jul 2021 17:57:22 -0400 Subject: [PATCH 4/6] chore: fix incorrect pathing to new preview function --- src/lib/helpers/setupNetlifyFunctionForPage.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/helpers/setupNetlifyFunctionForPage.js b/src/lib/helpers/setupNetlifyFunctionForPage.js index 3102f74e3e..9a7be22083 100644 --- a/src/lib/helpers/setupNetlifyFunctionForPage.js +++ b/src/lib/helpers/setupNetlifyFunctionForPage.js @@ -14,7 +14,8 @@ const { logItem } = require('./logger') // Create a Netlify Function for the page with the given file path const setupNetlifyFunctionForPage = async ({ filePath, functionsPath, isApiPage, isODB, forFallbackPreviewMode }) => { // Set function name based on file path - const functionName = getNetlifyFunctionName(filePath, isApiPage) + const defaultFunctionName = getNetlifyFunctionName(filePath, isApiPage) + const functionName = forFallbackPreviewMode ? getPreviewModeFunctionName(defaultFunctionName) : defaultFunctionName const functionDirectory = join(functionsPath, functionName) await ensureDir(functionDirectory) @@ -24,8 +25,7 @@ const setupNetlifyFunctionForPage = async ({ filePath, functionsPath, isApiPage, } // Write entry point to function directory - const fileName = forFallbackPreviewMode ? getPreviewModeFunctionName(functionName) : functionName - const entryPointPath = join(functionDirectory, `${fileName}.js`) + const entryPointPath = join(functionDirectory, `${functionName}.js`) await writeFile(entryPointPath, getTemplate({ filePath, isODB })) // Copy function helper From 5f46a9c9bd962775e177ac37c0baac5aec421d08 Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Thu, 29 Jul 2021 22:17:53 -0400 Subject: [PATCH 5/6] chore: add additional test --- src/tests/defaults.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tests/defaults.test.js b/src/tests/defaults.test.js index ef1732fd8e..13cebf603e 100644 --- a/src/tests/defaults.test.js +++ b/src/tests/defaults.test.js @@ -129,8 +129,14 @@ describe('SSG Pages with getStaticProps', () => { const functionPath1 = 'next_getStaticProps_withFallback_id/next_getStaticProps_withFallback_id.js' expect(existsSync(join(PROJECT_PATH, 'out_functions', functionPath1))).toBe(true) + const previewFunctionPath1 = 'preview-next_getStaticProps_withFallback_id/preview-next_getStaticProps_withFallback_id.js' + expect(existsSync(join(PROJECT_PATH, 'out_functions', previewFunctionPath1))).toBe(true) + const functionPath2 = 'next_getStaticProps_withFallback_slug/next_getStaticProps_withFallback_slug.js' expect(existsSync(join(PROJECT_PATH, 'out_functions', functionPath2))).toBe(true) + + const previewFunctionPath2 = 'preview-next_getStaticProps_withFallback_slug/preview-next_getStaticProps_withFallback_slug.js' + expect(existsSync(join(PROJECT_PATH, 'out_functions', previewFunctionPath2))).toBe(true) }) }) From f99bf6695c5f3acf7c6608ee3f9183d062b89fbf Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Sun, 1 Aug 2021 06:12:18 -0400 Subject: [PATCH 6/6] fix: revalidate pages with fallback werent getting new preview redirects --- src/lib/helpers/isRouteWithFallback.js | 2 ++ src/lib/pages/getStaticProps/pages.js | 9 ++++++--- src/tests/__snapshots__/basePath.test.js.snap | 6 ++++++ src/tests/__snapshots__/defaults.test.js.snap | 4 ++++ src/tests/__snapshots__/i18n.test.js.snap | 8 ++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/lib/helpers/isRouteWithFallback.js b/src/lib/helpers/isRouteWithFallback.js index 8f7631d2e1..5ed522b97b 100644 --- a/src/lib/helpers/isRouteWithFallback.js +++ b/src/lib/helpers/isRouteWithFallback.js @@ -1,6 +1,8 @@ const getPrerenderManifest = require('./getPrerenderManifest') const isRouteWithFallback = async (route) => { + if (!route) return false + const { dynamicRoutes } = await getPrerenderManifest() // Fallback "blocking" routes will have fallback: null in manifest diff --git a/src/lib/pages/getStaticProps/pages.js b/src/lib/pages/getStaticProps/pages.js index b091c4ed9f..fdb594e451 100644 --- a/src/lib/pages/getStaticProps/pages.js +++ b/src/lib/pages/getStaticProps/pages.js @@ -1,4 +1,6 @@ +const asyncForEach = require('../../helpers/asyncForEach') const getPrerenderManifest = require('../../helpers/getPrerenderManifest') +const isRouteWithFallback = require('../../helpers/isRouteWithFallback') // Get pages using getStaticProps const getPages = async () => { @@ -7,9 +9,10 @@ const getPages = async () => { // Collect pages const pages = [] - Object.entries(routes).forEach(([route, { dataRoute, initialRevalidateSeconds, srcRoute }]) => { - // Ignore pages with revalidate, these will need to be SSRed - if (initialRevalidateSeconds) return + await asyncForEach(Object.entries(routes), async ([route, { dataRoute, initialRevalidateSeconds, srcRoute }]) => { + // Ignore pages with revalidate (but no fallback), these will need to be SSRed + const isFallbackRoute = await isRouteWithFallback(srcRoute) + if (initialRevalidateSeconds && !isFallbackRoute) return pages.push({ route, diff --git a/src/tests/__snapshots__/basePath.test.js.snap b/src/tests/__snapshots__/basePath.test.js.snap index f7dfae214d..1c84ff5327 100644 --- a/src/tests/__snapshots__/basePath.test.js.snap +++ b/src/tests/__snapshots__/basePath.test.js.snap @@ -16,6 +16,8 @@ exports[`Routing creates Netlify redirects 1`] = ` /_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /_next/data/%BUILD_ID%/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 +/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/1.json /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/2.json /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /api/hello-background /foo/api/hello-background 301! /api/static /foo/api/static 301! /foo /.netlify/functions/next_index 200 @@ -45,6 +47,10 @@ exports[`Routing creates Netlify redirects 1`] = ` /foo/getStaticProps/withFallbackBlocking/4 /getStaticProps/withFallbackBlocking/4 200 /foo/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /foo/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 +/foo/getStaticProps/withRevalidate/withFallback/1 /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withRevalidate/withFallback/1 /getStaticProps/withRevalidate/withFallback/1 200 +/foo/getStaticProps/withRevalidate/withFallback/2 /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/foo/getStaticProps/withRevalidate/withFallback/2 /getStaticProps/withRevalidate/withFallback/2 200 /foo/static /static 200 /getServerSideProps/static /foo/getServerSideProps/static 301! /getStaticProps/with-revalidate /foo/getStaticProps/with-revalidate 301! diff --git a/src/tests/__snapshots__/defaults.test.js.snap b/src/tests/__snapshots__/defaults.test.js.snap index 5dcb78ae85..2ecad2a24d 100644 --- a/src/tests/__snapshots__/defaults.test.js.snap +++ b/src/tests/__snapshots__/defaults.test.js.snap @@ -24,6 +24,8 @@ exports[`Routing creates Netlify redirects 1`] = ` /_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /_next/data/%BUILD_ID%/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 +/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/1.json /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/2.json /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /api/hello-background /.netlify/functions/next_api_hello-background 200 /api/static /.netlify/functions/next_api_static 200 /getServerSideProps/static /.netlify/functions/next_getServerSideProps_static 200 @@ -39,6 +41,8 @@ exports[`Routing creates Netlify redirects 1`] = ` /getStaticProps/withFallbackBlocking/4 /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 +/getStaticProps/withRevalidate/withFallback/1 /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withRevalidate/withFallback/2 /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/getServerSideProps/all.json /.netlify/functions/next_getServerSideProps_all_slug 200 /_next/data/%BUILD_ID%/getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200 /_next/data/%BUILD_ID%/getServerSideProps/:id.json /.netlify/functions/next_getServerSideProps_id 200 diff --git a/src/tests/__snapshots__/i18n.test.js.snap b/src/tests/__snapshots__/i18n.test.js.snap index fab2b12134..21534bf48a 100644 --- a/src/tests/__snapshots__/i18n.test.js.snap +++ b/src/tests/__snapshots__/i18n.test.js.snap @@ -19,6 +19,8 @@ exports[`Routing creates Netlify redirects 1`] = ` /_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200 +/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/withFallback/1.json /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/withFallback/2.json /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /_next/data/%BUILD_ID%/es.json /.netlify/functions/next_index 200 /_next/data/%BUILD_ID%/es/getServerSideProps/static.json /.netlify/functions/next_getServerSideProps_static 200 /_next/data/%BUILD_ID%/es/getStaticProps/static.json /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data @@ -40,6 +42,8 @@ exports[`Routing creates Netlify redirects 1`] = ` /en/getStaticProps/withFallbackBlocking/4 /.netlify/functions/preview-next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data /en/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /en/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 +/en/getStaticProps/withRevalidate/withFallback/1 /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/en/getStaticProps/withRevalidate/withFallback/2 /.netlify/functions/preview-next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data /es /.netlify/functions/next_index 200 /es/getServerSideProps/static /.netlify/functions/next_getServerSideProps_static 200 /es/getStaticProps/static /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data @@ -66,6 +70,10 @@ exports[`Routing creates Netlify redirects 1`] = ` /getStaticProps/withFallbackBlocking/4 /en/getStaticProps/withFallbackBlocking/4 200 /getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 /getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200 +/getStaticProps/withRevalidate/withFallback/1 /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withRevalidate/withFallback/1 /en/getStaticProps/withRevalidate/withFallback/1 200 +/getStaticProps/withRevalidate/withFallback/2 /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data +/getStaticProps/withRevalidate/withFallback/2 /en/getStaticProps/withRevalidate/withFallback/2 200 /static /en/static.html 200 /_next/data/%BUILD_ID%/en/getServerSideProps/all.json /.netlify/functions/next_getServerSideProps_all_slug 200 /_next/data/%BUILD_ID%/en/getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200