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
65e209ac
Commit
65e209ac
authored
Feb 25, 2026
by
Will Binns-Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test sourcemaps
parent
57713d37
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
10 deletions
+91
-10
hot-reloader-turbopack.ts
packages/next/src/server/dev/hot-reloader-turbopack.ts
+44
-1
error-recovery.test.ts
test/development/acceptance-app/error-recovery.test.ts
+2
-2
hmr-client.ts
...bopack-ecmascript-runtime/js/src/nodejs/dev/hmr-client.ts
+23
-2
[turbopack]_runtime.js
...sts/snapshot/debug-ids/node/output/[turbopack]_runtime.js
+20
-3
[turbopack]_runtime.js.map
...snapshot/debug-ids/node/output/[turbopack]_runtime.js.map
+2
-2
No files found.
packages/next/src/server/dev/hot-reloader-turbopack.ts
View file @
65e209ac
...
@@ -155,12 +155,43 @@ type ServerHmrSubscriptions = Map<
...
@@ -155,12 +155,43 @@ type ServerHmrSubscriptions = Map<
AsyncIterableIterator
<
TurbopackResult
<
NodeJsHmrUpdate
>>
AsyncIterableIterator
<
TurbopackResult
<
NodeJsHmrUpdate
>>
>
>
type
HmrModuleEntry
=
NodeJsPartialHmrUpdate
[
'instruction'
][
'entries'
][
string
]
/**
* Annotates an HMR module entry's code with //# sourceURL and
* //# sourceMappingURL so Node.js can resolve stack frames from eval'd
* server HMR modules back to their original source files.
*
* This is a temporary workaround until the Turbopack binary is rebuilt
* with the updated hmr-client.ts which does this annotation inside
* evalModuleEntry using RUNTIME_ROOT. Once the binary is updated,
* this pre-annotation can be removed (duplicate annotations are harmless
* since V8 uses the last //# sourceURL comment).
*/
function
annotateHmrEntry
(
entry
:
HmrModuleEntry
,
distDir
:
string
):
HmrModuleEntry
{
const
[
chunkPath
,
moduleId
]
=
entry
.
url
.
split
(
'?'
,
2
)
const
fileHref
=
pathToFileURL
(
join
(
distDir
,
chunkPath
)).
href
const
sourceURL
=
moduleId
?
`
${
fileHref
}
?
${
moduleId
}
`
:
fileHref
let
code
=
entry
.
code
+
'
\
n
\
n//# sourceURL='
+
sourceURL
if
(
entry
.
map
)
{
code
+=
'
\
n//# sourceMappingURL=data:application/json;charset=utf-8;base64,'
+
Buffer
.
from
(
entry
.
map
).
toString
(
'base64'
)
}
return
{
...
entry
,
code
}
}
function
setupServerHmr
(
function
setupServerHmr
(
project
:
Project
,
project
:
Project
,
{
{
onUpdateFailed
,
onUpdateFailed
,
distDir
,
}:
{
}:
{
onUpdateFailed
:
()
=>
void
|
Promise
<
void
>
onUpdateFailed
:
()
=>
void
|
Promise
<
void
>
distDir
:
string
}
}
)
{
)
{
const
serverHmrSubscriptions
:
ServerHmrSubscriptions
=
new
Map
()
const
serverHmrSubscriptions
:
ServerHmrSubscriptions
=
new
Map
()
...
@@ -194,7 +225,18 @@ function setupServerHmr(
...
@@ -194,7 +225,18 @@ function setupServerHmr(
}
}
if
(
typeof
__turbopack_server_hmr_apply__
===
'function'
)
{
if
(
typeof
__turbopack_server_hmr_apply__
===
'function'
)
{
const
applied
=
__turbopack_server_hmr_apply__
(
update
)
const
annotatedEntries
:
NodeJsPartialHmrUpdate
[
'instruction'
][
'entries'
]
=
{}
for
(
const
[
key
,
entry
]
of
Object
.
entries
(
update
.
instruction
.
entries
))
{
annotatedEntries
[
key
]
=
annotateHmrEntry
(
entry
,
distDir
)
}
const
annotatedUpdate
:
NodeJsPartialHmrUpdate
=
{
...
update
,
instruction
:
{
...
update
.
instruction
,
entries
:
annotatedEntries
},
}
const
applied
=
__turbopack_server_hmr_apply__
(
annotatedUpdate
)
if
(
!
applied
)
{
if
(
!
applied
)
{
await
onUpdateFailed
()
await
onUpdateFailed
()
}
}
...
@@ -1806,6 +1848,7 @@ export async function createHotReloaderTurbopack(
...
@@ -1806,6 +1848,7 @@ export async function createHotReloaderTurbopack(
})
})
serverHmrSubscriptions
=
setupServerHmr
(
project
,
{
serverHmrSubscriptions
=
setupServerHmr
(
project
,
{
distDir
,
onUpdateFailed
:
async
()
=>
{
onUpdateFailed
:
async
()
=>
{
if
(
typeof
__next__clear_chunk_cache__
===
'function'
)
{
if
(
typeof
__next__clear_chunk_cache__
===
'function'
)
{
__next__clear_chunk_cache__
()
__next__clear_chunk_cache__
()
...
...
test/development/acceptance-app/error-recovery.test.ts
View file @
65e209ac
turbopack/crates/turbopack-ecmascript-runtime/js/src/nodejs/dev/hmr-client.ts
View file @
65e209ac
...
@@ -13,6 +13,28 @@ type NodeJsHmrPayload = {
...
@@ -13,6 +13,28 @@ type NodeJsHmrPayload = {
instruction
:
EcmascriptMergedUpdate
instruction
:
EcmascriptMergedUpdate
}
}
/**
* Annotates module entry code with //# sourceURL and //# sourceMappingURL so
* that Node.js can resolve stack frames from eval'd server HMR modules back to
* their original source files. Mirrors the browser's _eval in dev-backend-dom.ts.
*
* RUNTIME_ROOT, path, and url are available from earlier files in the
* concatenated runtime bundle (node-externals-utils.ts, runtime-base.ts).
*/
function
annotateEntryCode
(
entry
:
EcmascriptModuleEntry
):
string
{
const
[
chunkPath
,
moduleId
]
=
entry
.
url
.
split
(
'?'
,
2
)
const
absolutePath
=
path
.
resolve
(
RUNTIME_ROOT
,
chunkPath
)
const
fileHref
=
url
.
pathToFileURL
(
absolutePath
).
href
const
sourceURL
=
moduleId
?
`
${
fileHref
}
?
${
moduleId
}
`
:
fileHref
let
code
=
entry
.
code
+
'
\
n
\
n//# sourceURL='
+
sourceURL
if
(
entry
.
map
)
{
code
+=
'
\
n//# sourceMappingURL=data:application/json;charset=utf-8;base64,'
+
Buffer
.
from
(
entry
.
map
).
toString
(
'base64'
)
}
return
code
}
let
serverHmrUpdateHandler
:
((
msg
:
NodeJsHmrPayload
)
=>
void
)
|
null
=
null
let
serverHmrUpdateHandler
:
((
msg
:
NodeJsHmrPayload
)
=>
void
)
|
null
=
null
function
initializeServerHmr
(
function
initializeServerHmr
(
...
@@ -75,10 +97,9 @@ function handleNodejsUpdate(
...
@@ -75,10 +97,9 @@ function handleNodejsUpdate(
try
{
try
{
const
{
entries
=
{},
chunks
=
{}
}
=
instruction
const
{
entries
=
{},
chunks
=
{}
}
=
instruction
// Node.js eval function (no source maps)
const
evalModuleEntry
=
(
entry
:
EcmascriptModuleEntry
)
=>
{
const
evalModuleEntry
=
(
entry
:
EcmascriptModuleEntry
)
=>
{
// eslint-disable-next-line no-eval
// eslint-disable-next-line no-eval
return
(
0
,
eval
)(
entry
.
code
)
return
(
0
,
eval
)(
annotateEntryCode
(
entry
)
)
}
}
const
{
added
,
modified
}
=
computeChangedModules
(
const
{
added
,
modified
}
=
computeChangedModules
(
...
...
turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/node/output/[turbopack]_runtime.js
View file @
65e209ac
...
@@ -1466,7 +1466,25 @@ module.exports = (sourcePath)=>({
...
@@ -1466,7 +1466,25 @@ module.exports = (sourcePath)=>({
});
});
/// <reference path="../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../shared/runtime/dev-protocol.d.ts" />
/// <reference path="../../shared/runtime/hmr-runtime.ts" />
/// <reference path="../../shared/runtime/hmr-runtime.ts" />
/* eslint-disable @typescript-eslint/no-unused-vars */
let
serverHmrUpdateHandler
=
null
;
/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Annotates module entry code with //# sourceURL and //# sourceMappingURL so
* that Node.js can resolve stack frames from eval'd server HMR modules back to
* their original source files. Mirrors the browser's _eval in dev-backend-dom.ts.
*
* RUNTIME_ROOT, path, and url are available from earlier files in the
* concatenated runtime bundle (node-externals-utils.ts, runtime-base.ts).
*/
function
annotateEntryCode
(
entry
)
{
const
[
chunkPath
,
moduleId
]
=
entry
.
url
.
split
(
'?'
,
2
);
const
absolutePath
=
path
.
resolve
(
RUNTIME_ROOT
,
chunkPath
);
const
fileHref
=
url
.
pathToFileURL
(
absolutePath
).
href
;
const
sourceURL
=
moduleId
?
`
${
fileHref
}
?
${
moduleId
}
`
:
fileHref
;
let
code
=
entry
.
code
+
'
\
n
\
n//# sourceURL='
+
sourceURL
;
if
(
entry
.
map
)
{
code
+=
'
\
n//# sourceMappingURL=data:application/json;charset=utf-8;base64,'
+
Buffer
.
from
(
entry
.
map
).
toString
(
'base64'
);
}
return
code
;
}
let
serverHmrUpdateHandler
=
null
;
function
initializeServerHmr
(
moduleFactories
,
devModuleCache
)
{
function
initializeServerHmr
(
moduleFactories
,
devModuleCache
)
{
if
(
serverHmrUpdateHandler
!=
null
)
{
if
(
serverHmrUpdateHandler
!=
null
)
{
throw
new
Error
(
'[Server HMR] Server HMR client is already initialized'
);
throw
new
Error
(
'[Server HMR] Server HMR client is already initialized'
);
...
@@ -1508,10 +1526,9 @@ function initializeServerHmr(moduleFactories, devModuleCache) {
...
@@ -1508,10 +1526,9 @@ function initializeServerHmr(moduleFactories, devModuleCache) {
}
}
try
{
try
{
const
{
entries
=
{},
chunks
=
{}
}
=
instruction
;
const
{
entries
=
{},
chunks
=
{}
}
=
instruction
;
// Node.js eval function (no source maps)
const
evalModuleEntry
=
(
entry
)
=>
{
const
evalModuleEntry
=
(
entry
)
=>
{
// eslint-disable-next-line no-eval
// eslint-disable-next-line no-eval
return
(
0
,
eval
)(
entry
.
code
);
return
(
0
,
eval
)(
annotateEntryCode
(
entry
)
);
};
};
const
{
added
,
modified
}
=
computeChangedModules
(
entries
,
chunks
,
undefined
// no chunkModulesMap for Node.js
const
{
added
,
modified
}
=
computeChangedModules
(
entries
,
chunks
,
undefined
// no chunkModulesMap for Node.js
);
);
...
...
turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/node/output/[turbopack]_runtime.js.map
View file @
65e209ac
This diff is collapsed.
Click to expand it.
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