From 8969595465228f40c10e6b8dae84104485ad95c3 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 12 Jan 2022 19:26:52 +0000 Subject: [PATCH 1/2] fix: handle missing routes in manifest --- src/helpers/redirects.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/redirects.ts b/src/helpers/redirects.ts index e43cf52e13..2cf6e7e5b9 100644 --- a/src/helpers/redirects.ts +++ b/src/helpers/redirects.ts @@ -139,8 +139,8 @@ export const generateRedirects = async ({ ) } }) - // Add rewrites for all static SSR routes - staticRoutes.forEach((route) => { + // Add rewrites for all static SSR routes. This is Next 12+ + staticRoutes?.forEach((route) => { if (staticRoutePaths.has(route.page) || isApiRoute(route.page)) { // Prerendered static routes are either handled by the CDN or are ISR return From be3905a9c1316cfa6b602e9add457fc8e73df838 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Thu, 13 Jan 2022 10:26:04 +0000 Subject: [PATCH 2/2] chore: add test --- src/helpers/types.ts | 2 +- test/index.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/helpers/types.ts b/src/helpers/types.ts index 80501c6618..2ab68af1d6 100644 --- a/src/helpers/types.ts +++ b/src/helpers/types.ts @@ -46,7 +46,7 @@ export interface RoutesManifest { redirects: Redirect[] headers: Header[] dynamicRoutes: DynamicRoute[] - staticRoutes: StaticRoute[] + staticRoutes?: StaticRoute[] dataRoutes: DataRoute[] i18n: I18n rewrites: Rewrites diff --git a/test/index.js b/test/index.js index c9449266be..7539a494c3 100644 --- a/test/index.js +++ b/test/index.js @@ -409,6 +409,16 @@ describe('onBuild()', () => { expect(readFileSync(handlerFile, 'utf8')).toMatch(`require("../../../.next/required-server-files.json")`) expect(readFileSync(odbHandlerFile, 'utf8')).toMatch(`require("../../../.next/required-server-files.json")`) }) + + test('handles empty routesManifest.staticRoutes', async () => { + await moveNextDist() + const manifestPath = path.resolve('.next/routes-manifest.json') + const routesManifest = await readJson(manifestPath) + delete routesManifest.staticRoutes + await writeJSON(manifestPath, routesManifest) + // The function is supposed to return undefined, but we want to check if it throws + expect(await plugin.onBuild(defaultArgs)).toBeUndefined() + }) }) describe('onPostBuild', () => {