Skip to content

fix: handle routes-manifests without staticRoutes defined #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/helpers/redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface RoutesManifest {
redirects: Redirect[]
headers: Header[]
dynamicRoutes: DynamicRoute[]
staticRoutes: StaticRoute[]
staticRoutes?: StaticRoute[]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F

dataRoutes: DataRoute[]
i18n: I18n
rewrites: Rewrites
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down