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
f5054deb
Unverified
Commit
f5054deb
authored
Apr 24, 2025
by
Jiachi Liu
Committed by
GitHub
Apr 24, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[next-server] ensure prepare is done before preloading entry (#78454)
parent
06190595
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
2 deletions
+76
-2
base-server.ts
packages/next/src/server/base-server.ts
+4
-2
next-server.ts
packages/next/src/server/next-server.ts
+3
-0
layout.tsx
test/e2e/app-dir/instrumentation-order/app/layout.tsx
+8
-0
page.tsx
test/e2e/app-dir/instrumentation-order/app/page.tsx
+8
-0
instrumentation-order.test.ts
...p-dir/instrumentation-order/instrumentation-order.test.ts
+35
-0
instrumentation.ts
test/e2e/app-dir/instrumentation-order/instrumentation.ts
+12
-0
next.config.js
test/e2e/app-dir/instrumentation-order/next.config.js
+6
-0
No files found.
packages/next/src/server/base-server.ts
View file @
f5054deb
...
@@ -1720,9 +1720,11 @@ export default abstract class Server<
...
@@ -1720,9 +1720,11 @@ export default abstract class Server<
public
async
prepare
():
Promise
<
void
>
{
public
async
prepare
():
Promise
<
void
>
{
if
(
this
.
prepared
)
return
if
(
this
.
prepared
)
return
if
(
this
.
preparedPromise
===
null
)
{
// Get instrumentation module
// Get instrumentation module
if
(
!
this
.
instrumentation
)
{
this
.
instrumentation
=
await
this
.
loadInstrumentationModule
()
this
.
instrumentation
=
await
this
.
loadInstrumentationModule
()
}
if
(
this
.
preparedPromise
===
null
)
{
this
.
preparedPromise
=
this
.
prepareImpl
().
then
(()
=>
{
this
.
preparedPromise
=
this
.
prepareImpl
().
then
(()
=>
{
this
.
prepared
=
true
this
.
prepared
=
true
this
.
preparedPromise
=
null
this
.
preparedPromise
=
null
...
...
packages/next/src/server/next-server.ts
View file @
f5054deb
...
@@ -376,6 +376,9 @@ export default class NextNodeServer extends BaseServer<
...
@@ -376,6 +376,9 @@ export default class NextNodeServer extends BaseServer<
}
}
public
async
unstable_preloadEntries
():
Promise
<
void
>
{
public
async
unstable_preloadEntries
():
Promise
<
void
>
{
// Ensure prepare process will be finished before preloading entries.
await
this
.
prepare
()
const
appPathsManifest
=
this
.
getAppPathsManifest
()
const
appPathsManifest
=
this
.
getAppPathsManifest
()
const
pagesManifest
=
this
.
getPagesManifest
()
const
pagesManifest
=
this
.
getPagesManifest
()
...
...
test/e2e/app-dir/instrumentation-order/app/layout.tsx
0 → 100644
View file @
f5054deb
import
{
ReactNode
}
from
'react'
export
default
function
Root
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
html
>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/instrumentation-order/app/page.tsx
0 → 100644
View file @
f5054deb
import
{
connection
}
from
'next/server'
console
.
log
(
'global-side-effect:app-router-page'
)
export
default
async
function
Page
()
{
await
connection
()
return
<
p
>
hello world
</
p
>
}
test/e2e/app-dir/instrumentation-order/instrumentation-order.test.ts
0 → 100644
View file @
f5054deb
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
waitFor
}
from
'next-test-utils'
const
ORDERED_LOGS
=
[
'instrumentation:side-effect'
,
'instrumentation:register:begin'
,
'instrumentation:register:timeout'
,
'instrumentation:register:end'
,
'global-side-effect:app-router-page'
,
]
describe
(
'instrumentation-order'
,
()
=>
{
const
{
next
,
isNextDev
}
=
nextTestSetup
({
files
:
__dirname
,
skipDeployment
:
true
,
})
it
(
'should work using cheerio'
,
async
()
=>
{
// Wait for the timeout in the instrumentation to complete
await
waitFor
(
500
)
// Dev mode requires to render the page to trigger the build of the page
if
(
isNextDev
)
{
await
next
.
render$
(
'/'
)
}
const
serverLog
=
next
.
cliOutput
.
split
(
'Starting...'
)[
1
]
const
cliOutputLines
=
serverLog
.
split
(
'
\
n'
)
const
searchedLines
=
cliOutputLines
.
filter
((
line
)
=>
ORDERED_LOGS
.
includes
(
line
.
trim
())
)
expect
(
searchedLines
).
toEqual
(
ORDERED_LOGS
)
})
})
test/e2e/app-dir/instrumentation-order/instrumentation.ts
0 → 100644
View file @
f5054deb
console
.
log
(
'instrumentation:side-effect'
)
export
async
function
register
()
{
console
.
log
(
'instrumentation:register:begin'
)
await
new
Promise
((
resolve
)
=>
{
setTimeout
(()
=>
{
console
.
log
(
'instrumentation:register:timeout'
)
resolve
(
true
)
},
300
)
})
console
.
log
(
'instrumentation:register:end'
)
}
test/e2e/app-dir/instrumentation-order/next.config.js
0 → 100644
View file @
f5054deb
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{}
module
.
exports
=
nextConfig
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