Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
8a92f28f
Unverified
Commit
8a92f28f
authored
Aug 25, 2025
by
Ben Gubler
Committed by
GitHub
Aug 25, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[backport] fix: avoid importing types that will be unused (#82856) (#83026)
parent
19617abe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
+24
-3
typegen.ts
packages/next/src/server/lib/router-utils/typegen.ts
+24
-3
No files found.
packages/next/src/server/lib/router-utils/typegen.ts
View file @
8a92f28f
...
...
@@ -579,7 +579,23 @@ export function generateValidatorFile(
}
// Build import statement based on what's actually needed
const
routeImports
=
[
'AppRoutes'
,
'LayoutRoutes'
,
'ParamMap'
]
const
routeImports
=
[]
// Only import AppRoutes if there are app pages
if
(
appPageValidations
)
{
routeImports
.
push
(
'AppRoutes'
)
}
// Only import LayoutRoutes if there are layouts
if
(
layoutValidations
)
{
routeImports
.
push
(
'LayoutRoutes'
)
}
// Only import ParamMap if there are routes that use it
if
(
appPageValidations
||
layoutValidations
||
appRouteHandlerValidations
)
{
routeImports
.
push
(
'ParamMap'
)
}
if
(
hasAppRouteHandlers
)
{
routeImports
.
push
(
'AppRouteHandlerRoutes'
)
}
...
...
@@ -593,13 +609,18 @@ export function generateValidatorFile(
?
"import type { NextRequest } from 'next/server.js'
\n
"
:
''
// Only import metadata types if there are App Router pages or layouts that might use them
const
metadataImport
=
appPageValidations
||
layoutValidations
?
'import type { ResolvingMetadata, ResolvingViewport } from "next/dist/lib/metadata/types/metadata-interface.js"
\
n'
:
''
return
`// This file is generated automatically by Next.js
// Do not edit this file manually
// This file validates that all pages and layouts export the correct types
${
routeImportStatement
}
import type { ResolvingMetadata, ResolvingViewport } from "next/dist/lib/metadata/types/metadata-interface.js"
${
nextRequestImport
}
${
metadataImport
}${
nextRequestImport
}
${
typeDefinitions
}
${
appPageValidations
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment