Skip to content

Commit 96f3ccb

Browse files
fix: handle routes-manifests without staticRoutes defined (#1120)
* fix: handle missing routes in manifest * chore: add test Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 856f838 commit 96f3ccb

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/helpers/redirects.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ export const generateRedirects = async ({
139139
)
140140
}
141141
})
142-
// Add rewrites for all static SSR routes
143-
staticRoutes.forEach((route) => {
142+
// Add rewrites for all static SSR routes. This is Next 12+
143+
staticRoutes?.forEach((route) => {
144144
if (staticRoutePaths.has(route.page) || isApiRoute(route.page)) {
145145
// Prerendered static routes are either handled by the CDN or are ISR
146146
return

src/helpers/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface RoutesManifest {
4646
redirects: Redirect[]
4747
headers: Header[]
4848
dynamicRoutes: DynamicRoute[]
49-
staticRoutes: StaticRoute[]
49+
staticRoutes?: StaticRoute[]
5050
dataRoutes: DataRoute[]
5151
i18n: I18n
5252
rewrites: Rewrites

test/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,16 @@ describe('onBuild()', () => {
409409
expect(readFileSync(handlerFile, 'utf8')).toMatch(`require("../../../.next/required-server-files.json")`)
410410
expect(readFileSync(odbHandlerFile, 'utf8')).toMatch(`require("../../../.next/required-server-files.json")`)
411411
})
412+
413+
test('handles empty routesManifest.staticRoutes', async () => {
414+
await moveNextDist()
415+
const manifestPath = path.resolve('.next/routes-manifest.json')
416+
const routesManifest = await readJson(manifestPath)
417+
delete routesManifest.staticRoutes
418+
await writeJSON(manifestPath, routesManifest)
419+
// The function is supposed to return undefined, but we want to check if it throws
420+
expect(await plugin.onBuild(defaultArgs)).toBeUndefined()
421+
})
412422
})
413423

414424
describe('onPostBuild', () => {

0 commit comments

Comments
 (0)