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
329bcdc7
Unverified
Commit
329bcdc7
authored
Jul 24, 2025
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Jul 24, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[devtools] Fix "open in editor" for locations in stackframes (#82013)
parent
504fa32a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
19 deletions
+39
-19
launch-editor.ts
packages/next/src/next-devtools/server/launch-editor.ts
+25
-6
middleware-turbopack.ts
packages/next/src/server/dev/middleware-turbopack.ts
+8
-5
middleware-webpack.ts
packages/next/src/server/dev/middleware-webpack.ts
+6
-8
No files found.
packages/next/src/next-devtools/server/launch-editor.ts
View file @
329bcdc7
...
...
@@ -27,6 +27,7 @@ import fs from 'fs'
import
fsp
from
'fs/promises'
import
os
from
'os'
import
path
from
'path'
import
{
fileURLToPath
}
from
'url'
import
shellQuote
from
'next/dist/compiled/shell-quote'
function
isTerminalEditor
(
editor
:
string
)
{
...
...
@@ -426,15 +427,33 @@ export function launchEditor(fileName: string, line1: number, column1: number) {
}
}
// Open the file in editor if exists, otherwise return an error
/**
* Open the file in editor if exists, otherwise return an error
* @param file `file:` URL, or absolute path or relative path. Relative paths must
* relative to `nextRootDirectory`.
*/
export
async
function
openFileInEditor
(
file
Path
:
string
,
file
:
string
,
line1
:
number
,
column1
:
number
)
{
column1
:
number
,
nextRootDirectory
:
string
):
Promise
<
{
found
:
boolean
;
error
:
unknown
|
null
}
>
{
let
filePath
:
string
if
(
file
.
startsWith
(
'file://'
))
{
try
{
filePath
=
fileURLToPath
(
file
)
}
catch
(
error
)
{
return
{
found
:
false
,
error
}
}
}
else
if
(
path
.
isAbsolute
(
file
))
{
filePath
=
file
}
else
{
filePath
=
path
.
join
(
nextRootDirectory
,
file
)
}
const
result
=
{
found
:
false
,
error
:
null
as
Error
|
null
,
error
:
null
as
unknown
|
null
,
}
const
existed
=
await
fsp
.
access
(
filePath
,
fs
.
constants
.
F_OK
).
then
(
()
=>
true
,
...
...
@@ -445,7 +464,7 @@ export async function openFileInEditor(
launchEditor
(
filePath
,
line1
,
column1
)
result
.
found
=
true
}
catch
(
err
)
{
result
.
error
=
err
as
Error
result
.
error
=
err
}
}
return
result
...
...
packages/next/src/server/dev/middleware-turbopack.ts
View file @
329bcdc7
...
...
@@ -370,25 +370,28 @@ export function getOverlayMiddleware({
let
openEditorResult
if
(
isAppRelativePath
)
{
const
relativeFilePath
=
searchParams
.
get
(
'file'
)
||
''
const
absoluteFilePath
=
path
.
join
(
projectPath
,
const
appPath
=
path
.
join
(
'app'
,
isSrcDir
?
'src'
:
''
,
relativeFilePath
)
openEditorResult
=
await
openFileInEditor
(
a
bsoluteFilePath
,
1
,
1
)
openEditorResult
=
await
openFileInEditor
(
a
ppPath
,
1
,
1
,
projectPath
)
}
else
{
const
frame
=
createStackFrame
(
searchParams
)
if
(
!
frame
)
return
middlewareResponse
.
badRequest
(
res
)
openEditorResult
=
await
openFileInEditor
(
frame
.
file
,
frame
.
line
??
1
,
frame
.
column
??
1
frame
.
column
??
1
,
projectPath
)
}
if
(
openEditorResult
.
error
)
{
return
middlewareResponse
.
internalServerError
(
res
)
return
middlewareResponse
.
internalServerError
(
res
,
openEditorResult
.
error
)
}
if
(
!
openEditorResult
.
found
)
{
return
middlewareResponse
.
notFound
(
res
)
...
...
packages/next/src/server/dev/middleware-webpack.ts
View file @
329bcdc7
...
...
@@ -600,23 +600,21 @@ export function getOverlayMiddleware(options: {
const
isAppRelativePath
=
searchParams
.
get
(
'isAppRelativePath'
)
===
'1'
if
(
isAppRelativePath
)
{
const
relativeFilePath
=
searchParams
.
get
(
'file'
)
||
''
const
absoluteFilePath
=
path
.
join
(
rootDirectory
,
const
appPath
=
path
.
join
(
'app'
,
isSrcDir
?
'src'
:
''
,
relativeFilePath
)
openEditorResult
=
await
openFileInEditor
(
a
bsoluteFilePath
,
1
,
1
)
openEditorResult
=
await
openFileInEditor
(
a
ppPath
,
1
,
1
,
rootDirectory
)
}
else
{
// TODO: How do we differentiate layers and actual file paths with round brackets?
// frame files may start with their webpack layer, like (middleware)/middleware.js
const
filePath
=
path
.
resolve
(
rootDirectory
,
frame
.
file
.
replace
(
/^
\([^
)
]
+
\)\/
/
,
''
)
)
const
filePath
=
frame
.
file
.
replace
(
/^
\([^
)
]
+
\)\/
/
,
''
)
openEditorResult
=
await
openFileInEditor
(
filePath
,
frame
.
line1
,
frame
.
column1
??
1
frame
.
column1
??
1
,
rootDirectory
)
}
if
(
openEditorResult
.
error
)
{
...
...
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