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
1c5680e9
Commit
1c5680e9
authored
Mar 19, 2026
by
Will Binns-Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
62393b04
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
175 additions
and
14 deletions
+175
-14
instrumentation.rs
crates/next-api/src/instrumentation.rs
+22
-5
middleware.rs
crates/next-api/src/middleware.rs
+20
-3
hot-reloader-turbopack.ts
packages/next/src/server/dev/hot-reloader-turbopack.ts
+9
-6
route.ts
...app-dir/server-hmr/app/api/instrumentation-state/route.ts
+7
-0
instrumentation-dep.ts
test/development/app-dir/server-hmr/instrumentation-dep.ts
+2
-0
instrumentation.ts
test/development/app-dir/server-hmr/instrumentation.ts
+7
-0
middleware-dep.ts
test/development/app-dir/server-hmr/middleware-dep.ts
+2
-0
middleware.ts
test/development/app-dir/server-hmr/middleware.ts
+10
-0
server-hmr.test.ts
test/development/app-dir/server-hmr/server-hmr.test.ts
+96
-0
No files found.
crates/next-api/src/instrumentation.rs
View file @
1c5680e9
use
anyhow
::
Result
;
use
anyhow
::
{
Context
,
Result
}
;
use
next_core
::{
next_edge
::
entry
::
wrap_edge_entry
,
next_manifests
::{
InstrumentationDefinition
,
MiddlewaresManifestV2
},
...
...
@@ -213,13 +213,30 @@ impl Endpoint for InstrumentationEndpoint {
vec!
[]
};
Ok
(
EndpointOutput
{
output_assets
:
output_assets
.to_resolved
()
.await
?
,
output_paths
:
EndpointOutputPaths
::
Edge
{
let
output_paths
=
if
!
this
.is_edge
{
let
node_root
=
this
.project
.node_root
()
.owned
()
.await
?
;
let
chunk
=
self
.node_chunk
();
let
server_entry_path
=
node_root
.get_path_to
(
&*
chunk
.path
()
.await
?
)
.context
(
"Node.js instrumentation chunk entry path must be inside the node root"
,
)
?
.into
();
EndpointOutputPaths
::
NodeJs
{
server_entry_path
,
server_paths
,
client_paths
:
vec!
[],
}
.resolved_cell
(),
}
else
{
EndpointOutputPaths
::
Edge
{
server_paths
,
client_paths
:
vec!
[],
}
};
Ok
(
EndpointOutput
{
output_assets
:
output_assets
.to_resolved
()
.await
?
,
output_paths
:
output_paths
.resolved_cell
(),
project
:
this
.project
,
}
.cell
())
...
...
crates/next-api/src/middleware.rs
View file @
1c5680e9
...
...
@@ -359,12 +359,29 @@ impl Endpoint for MiddlewareEndpoint {
(
vec!
[],
vec!
[])
};
Ok
(
EndpointOutput
{
output_paths
:
EndpointOutputPaths
::
Edge
{
let
output_paths
=
if
matches!
(
this
.runtime
,
NextRuntime
::
NodeJs
)
{
let
node_root
=
this
.project
.node_root
()
.owned
()
.await
?
;
let
chunk
=
self
.node_chunk
();
let
server_entry_path
=
node_root
.get_path_to
(
&*
chunk
.path
()
.await
?
)
.context
(
"Node.js middleware chunk entry path must be inside the node root"
,
)
?
.into
();
EndpointOutputPaths
::
NodeJs
{
server_entry_path
,
server_paths
,
client_paths
,
}
.resolved_cell
(),
}
else
{
EndpointOutputPaths
::
Edge
{
server_paths
,
client_paths
,
}
};
Ok
(
EndpointOutput
{
output_paths
:
output_paths
.resolved_cell
(),
output_assets
:
output_assets
.to_resolved
()
.await
?
,
project
:
this
.project
,
}
...
...
packages/next/src/server/dev/hot-reloader-turbopack.ts
View file @
1c5680e9
...
...
@@ -602,15 +602,18 @@ export async function createHotReloaderTurbopack(
join
(
distDir
,
p
)
)
const
{
type
:
entryType
}
=
splitEntryKey
(
key
)
const
{
type
:
entryType
,
page
:
entryPage
}
=
splitEntryKey
(
key
)
// Server HMR applies to
all App Router entries built with the Turbopack
// Node.js
runtime: both app pages and route handlers. Edge routes,
//
Pages Router pages, and middleware/instrumentation do not use the
// Turbopack Node.js dev runtime and are excluded.
// Server HMR applies to
App Router entries, Node.js middleware, and
// Node.js
instrumentation built with the Turbopack Node.js runtime. Edge
//
routes, Pages Router pages, and edge middleware/instrumentation do not
//
use the
Turbopack Node.js dev runtime and are excluded.
const
usesServerHmr
=
serverFastRefresh
&&
entryType
===
'app'
&&
(
entryType
===
'app'
||
(
entryType
===
'root'
&&
(
entryPage
===
'middleware'
||
entryPage
===
'instrumentation.nodeJs'
)))
&&
writtenEndpoint
.
type
!==
'edge'
const
filesToDelete
:
string
[]
=
[]
...
...
test/development/app-dir/server-hmr/app/api/instrumentation-state/route.ts
0 → 100644
View file @
1c5680e9
export
function
GET
()
{
return
Response
.
json
({
version
:
(
globalThis
as
any
).
__instrumentationVersion
??
'not-set'
,
depEvaluatedAt
:
(
globalThis
as
any
).
__instrumentationDepEvaluatedAt
??
'not-set'
,
})
}
test/development/app-dir/server-hmr/instrumentation-dep.ts
0 → 100644
View file @
1c5680e9
export
const
_hmrTrigger
=
0
export
const
instrumentationDepEvaluatedAt
=
Date
.
now
()
test/development/app-dir/server-hmr/instrumentation.ts
0 → 100644
View file @
1c5680e9
import
{
instrumentationDepEvaluatedAt
}
from
'./instrumentation-dep'
// Set at module scope so server HMR re-evaluation updates these globals
;(
globalThis
as
any
).
__instrumentationVersion
=
'v0'
;(
globalThis
as
any
).
__instrumentationDepEvaluatedAt
=
instrumentationDepEvaluatedAt
export
function
register
()
{}
test/development/app-dir/server-hmr/middleware-dep.ts
0 → 100644
View file @
1c5680e9
export
const
_hmrTrigger
=
0
export
const
depEvaluatedAt
=
Date
.
now
()
test/development/app-dir/server-hmr/middleware.ts
0 → 100644
View file @
1c5680e9
export
const
runtime
=
'nodejs'
import
{
NextResponse
}
from
'next/server'
import
{
depEvaluatedAt
}
from
'./middleware-dep'
export
default
function
middleware
()
{
const
res
=
NextResponse
.
next
()
res
.
headers
.
set
(
'x-middleware-version'
,
'0'
)
res
.
headers
.
set
(
'x-middleware-dep-evaluated-at'
,
String
(
depEvaluatedAt
))
return
res
}
test/development/app-dir/server-hmr/server-hmr.test.ts
View file @
1c5680e9
...
...
@@ -155,6 +155,102 @@ describe('server-hmr', () => {
)
})
describe
(
'nodejs middleware hmr'
,
()
=>
{
it
(
'reflects Node.js middleware changes on next request'
,
async
()
=>
{
const
initial
=
await
next
.
fetch
(
'/api/hello'
)
expect
(
initial
.
headers
.
get
(
'x-middleware-version'
)).
toBe
(
'0'
)
await
next
.
patchFile
(
'middleware.ts'
,
(
content
)
=>
content
.
replace
(
"'0'"
,
"'1'"
)
)
await
retry
(
async
()
=>
{
const
updated
=
await
next
.
fetch
(
'/api/hello'
)
expect
(
updated
.
headers
.
get
(
'x-middleware-version'
)).
toBe
(
'1'
)
})
})
itTurbopackDev
(
'does not re-evaluate unmodified dependency when middleware changes'
,
async
()
=>
{
// Read current version (may have been changed by a previous test)
const
initial
=
await
next
.
fetch
(
'/api/hello'
)
const
initialVersion
=
initial
.
headers
.
get
(
'x-middleware-version'
)
const
initialDepEvaluatedAt
=
initial
.
headers
.
get
(
'x-middleware-dep-evaluated-at'
)
expect
(
initialDepEvaluatedAt
).
toMatch
(
/^
\d
+$/
)
// Change only the middleware, not the dependency
await
next
.
patchFile
(
'middleware.ts'
,
(
content
)
=>
content
.
replace
(
`'
${
initialVersion
}
'`
,
`'
${
initialVersion
}
-updated'`
)
)
await
retry
(
async
()
=>
{
const
updated
=
await
next
.
fetch
(
'/api/hello'
)
expect
(
updated
.
headers
.
get
(
'x-middleware-version'
)).
toBe
(
`
${
initialVersion
}
-updated`
)
// The unmodified dependency should NOT have been re-evaluated
expect
(
updated
.
headers
.
get
(
'x-middleware-dep-evaluated-at'
)
).
toBe
(
initialDepEvaluatedAt
)
})
}
)
})
describe
(
'instrumentation hmr'
,
()
=>
{
itTurbopackDev
(
'reflects instrumentation module changes via server HMR'
,
async
()
=>
{
const
initial
=
await
next
.
fetch
(
'/api/instrumentation-state'
)
.
then
((
res
)
=>
res
.
json
())
expect
(
initial
.
version
).
toBe
(
'v0'
)
await
next
.
patchFile
(
'instrumentation.ts'
,
(
content
)
=>
content
.
replace
(
"'v0'"
,
"'v1'"
)
)
await
retry
(
async
()
=>
{
const
updated
=
await
next
.
fetch
(
'/api/instrumentation-state'
)
.
then
((
res
)
=>
res
.
json
())
expect
(
updated
.
version
).
toBe
(
'v1'
)
})
}
)
itTurbopackDev
(
'does not re-evaluate unmodified dependency when instrumentation changes'
,
async
()
=>
{
// Read current state (version may have changed in prior test)
const
initial
=
await
next
.
fetch
(
'/api/instrumentation-state'
)
.
then
((
res
)
=>
res
.
json
())
const
initialDepEvaluatedAt
=
initial
.
depEvaluatedAt
expect
(
String
(
initialDepEvaluatedAt
)).
toMatch
(
/^
\d
+$/
)
// Change only instrumentation, not the dependency
await
next
.
patchFile
(
'instrumentation.ts'
,
(
content
)
=>
content
.
replace
(
`'
${
initial
.
version
}
'`
,
`'
${
initial
.
version
}
-updated'`
)
)
await
retry
(
async
()
=>
{
const
updated
=
await
next
.
fetch
(
'/api/instrumentation-state'
)
.
then
((
res
)
=>
res
.
json
())
expect
(
updated
.
version
).
toBe
(
`
${
initial
.
version
}
-updated`
)
// The unmodified dependency should NOT have been re-evaluated
expect
(
String
(
updated
.
depEvaluatedAt
)).
toBe
(
String
(
initialDepEvaluatedAt
)
)
})
}
)
})
describe
(
'route handler hmr'
,
()
=>
{
function
getText
(
res
:
Response
)
{
return
res
.
ok
...
...
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