Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 17 additions & 3 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,31 @@ impl DebugBuildPathsRouteKeys {
.iter()
.map(|path| {
// Pages router: "/foo.tsx" -> "/foo"
// Also: "/foo/index.tsx" -> "/foo" (strip "/index" suffix).
// Catch-all routes like "/foo/[...slug]" contain dots in the segment name;
// only treat the suffix as an extension when it is a plain alphanumeric token.
let file_name = path.rsplit('/').next().unwrap_or(path);
if let Some(dot_idx) = file_name.rfind('.') {
let mut result: RcStr = if let Some(dot_idx) = file_name.rfind('.') {
let ext = &file_name[dot_idx + 1..];
if !ext.is_empty() && ext.chars().all(|c| c.is_ascii_alphanumeric()) {
let trimmed_len = path.len() - (file_name.len() - dot_idx);
return path[..trimmed_len].into();
path[..trimmed_len].into()
} else {
path.clone()
}
} else {
path.clone()
};

if let Some(stripped) = result.strip_suffix("/index") {
result = if stripped.is_empty() {
"/".into()
} else {
stripped.into()
};
}
path.clone()

result
})
.collect(),
})
Expand Down
14 changes: 14 additions & 0 deletions test/production/debug-build-path/debug-build-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ describe('debug-build-paths', () => {
expect(buildResult.cliOutput).not.toContain('Route (app)')
})

it('should include pages index routes with debug-prerender', async () => {
const buildResult = await next.build({
args: ['--debug-prerender', '--debug-build-paths', 'pages/**'],
})
expect(buildResult.exitCode).toBe(0)
expect(buildResult.cliOutput).toBeDefined()

expect(buildResult.cliOutput).toContain('Route (pages)')
expect(buildResult.cliOutput).toContain('○ /with-index')
expect(buildResult.cliOutput).not.toContain(
'Cannot find module for page'
)
})

it('should build multiple pages routes', async () => {
const buildResult = await next.build({
args: ['--debug-build-paths', 'pages/foo.tsx,pages/bar.tsx'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function WithIndexPage() {
return <main>With index page</main>
}
Loading