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
cf07866e
Unverified
Commit
cf07866e
authored
Jan 29, 2026
by
Niklas Mischkulnig
Committed by
GitHub
Jan 29, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort prerender manifest routes (#89246)
Closes PACK-6753
parent
47c35078
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
index.ts
packages/next/src/build/index.ts
+5
-2
sortable-routes.ts
packages/next/src/shared/lib/router/utils/sortable-routes.ts
+22
-0
No files found.
packages/next/src/build/index.ts
View file @
cf07866e
...
@@ -222,6 +222,7 @@ import { handleBuildComplete } from './adapter/build-complete'
...
@@ -222,6 +222,7 @@ import { handleBuildComplete } from './adapter/build-complete'
import
{
import
{
sortPageObjects
,
sortPageObjects
,
sortPages
,
sortPages
,
sortPagesObject
,
sortSortableRouteObjects
,
sortSortableRouteObjects
,
}
from
'../shared/lib/router/utils/sortable-routes'
}
from
'../shared/lib/router/utils/sortable-routes'
import
{
cp
,
mkdir
,
writeFile
}
from
'fs/promises'
import
{
cp
,
mkdir
,
writeFile
}
from
'fs/promises'
...
@@ -546,11 +547,13 @@ async function readManifest<T extends object>(filePath: string): Promise<T> {
...
@@ -546,11 +547,13 @@ async function readManifest<T extends object>(filePath: string): Promise<T> {
async
function
writePrerenderManifest
(
async
function
writePrerenderManifest
(
distDir
:
string
,
distDir
:
string
,
manifest
:
DeepReadonly
<
PrerenderManifest
>
manifest
:
PrerenderManifest
):
Promise
<
void
>
{
):
Promise
<
void
>
{
// Sort for deterministic outputs
manifest
.
routes
=
sortPagesObject
(
manifest
.
routes
)
manifest
.
dynamicRoutes
=
sortPagesObject
(
manifest
.
dynamicRoutes
)
await
writeManifest
(
path
.
join
(
distDir
,
PRERENDER_MANIFEST
),
manifest
)
await
writeManifest
(
path
.
join
(
distDir
,
PRERENDER_MANIFEST
),
manifest
)
}
}
async
function
writeClientSsgManifest
(
async
function
writeClientSsgManifest
(
prerenderManifest
:
DeepReadonly
<
PrerenderManifest
>
,
prerenderManifest
:
DeepReadonly
<
PrerenderManifest
>
,
{
{
...
...
packages/next/src/shared/lib/router/utils/sortable-routes.ts
View file @
cf07866e
...
@@ -179,6 +179,28 @@ export function sortPages(pages: readonly string[]): readonly string[] {
...
@@ -179,6 +179,28 @@ export function sortPages(pages: readonly string[]): readonly string[] {
return
[...
pages
].
sort
(
compareRouteSegments
)
return
[...
pages
].
sort
(
compareRouteSegments
)
}
}
/**
* Sorts an object by specificity of the keys using a deterministic depth-first traversal approach.
*
* @param obj - object of pages to sort
* @returns New sorted object (does not mutate input)
*/
export
function
sortPagesObject
<
T
>
(
obj
:
Readonly
<
Record
<
string
,
T
>>
):
Record
<
string
,
T
>
{
// Because sort is always in-place, we need to create a shallow copy to avoid
// mutating the input.
return
Object
.
keys
(
obj
)
.
sort
(
compareRouteSegments
)
.
reduce
(
(
acc
,
key
)
=>
{
acc
[
key
]
=
obj
[
key
]
return
acc
},
{}
as
Record
<
string
,
T
>
)
}
/**
/**
* Sorts an array of objects by sourcePage and page using a deterministic
* Sorts an array of objects by sourcePage and page using a deterministic
* depth-first traversal approach.
* depth-first traversal approach.
...
...
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