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
5bdf9154
Unverified
Commit
5bdf9154
authored
Oct 22, 2024
by
Jiachi Liu
Committed by
GitHub
Oct 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: next package resolving in dev overlay (#71632)
parent
4ee184b8
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
144 additions
and
55 deletions
+144
-55
create-compiler-aliases.ts
packages/next/src/build/create-compiler-aliases.ts
+2
-1
next-dir-paths.ts
packages/next/src/build/next-dir-paths.ts
+8
-0
webpack-config.ts
packages/next/src/build/webpack-config.ts
+4
-7
CallStackFrame.tsx
...verlay/internal/container/RuntimeError/CallStackFrame.tsx
+5
-1
stack-frame.ts
...ponents/react-dev-overlay/internal/helpers/stack-frame.ts
+1
-37
webpack-module-path.test.ts
...-dev-overlay/internal/helpers/webpack-module-path.test.ts
+68
-0
webpack-module-path.ts
...react-dev-overlay/internal/helpers/webpack-module-path.ts
+36
-0
middleware.ts
.../client/components/react-dev-overlay/server/middleware.ts
+16
-3
ReactRefreshLogBox.test.ts
test/development/acceptance-app/ReactRefreshLogBox.test.ts
+4
-6
No files found.
packages/next/src/build/create-compiler-aliases.ts
View file @
5bdf9154
...
@@ -14,7 +14,8 @@ import {
...
@@ -14,7 +14,8 @@ import {
}
from
'../lib/constants'
}
from
'../lib/constants'
import
type
{
NextConfigComplete
}
from
'../server/config-shared'
import
type
{
NextConfigComplete
}
from
'../server/config-shared'
import
{
defaultOverrides
}
from
'../server/require-hook'
import
{
defaultOverrides
}
from
'../server/require-hook'
import
{
NEXT_PROJECT_ROOT
,
hasExternalOtelApiPackage
}
from
'./webpack-config'
import
{
hasExternalOtelApiPackage
}
from
'./webpack-config'
import
{
NEXT_PROJECT_ROOT
}
from
'./next-dir-paths'
import
{
WEBPACK_LAYERS
}
from
'../lib/constants'
import
{
WEBPACK_LAYERS
}
from
'../lib/constants'
import
{
isWebpackServerOnlyLayer
}
from
'./utils'
import
{
isWebpackServerOnlyLayer
}
from
'./utils'
...
...
packages/next/src/build/next-dir-paths.ts
0 → 100644
View file @
5bdf9154
import
path
from
'path'
export
const
NEXT_PROJECT_ROOT
=
path
.
join
(
__dirname
,
'..'
,
'..'
)
export
const
NEXT_PROJECT_ROOT_DIST
=
path
.
join
(
NEXT_PROJECT_ROOT
,
'dist'
)
export
const
NEXT_PROJECT_ROOT_DIST_CLIENT
=
path
.
join
(
NEXT_PROJECT_ROOT_DIST
,
'client'
)
packages/next/src/build/webpack-config.ts
View file @
5bdf9154
...
@@ -89,6 +89,10 @@ import {
...
@@ -89,6 +89,10 @@ import {
getReactCompilerLoader
,
getReactCompilerLoader
,
}
from
'./get-babel-loader-config'
}
from
'./get-babel-loader-config'
import
type
{
NextFlightLoaderOptions
}
from
'./webpack/loaders/next-flight-loader'
import
type
{
NextFlightLoaderOptions
}
from
'./webpack/loaders/next-flight-loader'
import
{
NEXT_PROJECT_ROOT
,
NEXT_PROJECT_ROOT_DIST_CLIENT
,
}
from
'./next-dir-paths'
type
ExcludesFalse
=
<
T
>
(
x
:
T
|
false
)
=>
x
is
T
type
ExcludesFalse
=
<
T
>
(
x
:
T
|
false
)
=>
x
is
T
type
ClientEntries
=
{
type
ClientEntries
=
{
...
@@ -101,13 +105,6 @@ const EXTERNAL_PACKAGES =
...
@@ -101,13 +105,6 @@ const EXTERNAL_PACKAGES =
const
DEFAULT_TRANSPILED_PACKAGES
=
const
DEFAULT_TRANSPILED_PACKAGES
=
require
(
'../lib/default-transpiled-packages.json'
)
as
string
[]
require
(
'../lib/default-transpiled-packages.json'
)
as
string
[]
export
const
NEXT_PROJECT_ROOT
=
path
.
join
(
__dirname
,
'..'
,
'..'
)
export
const
NEXT_PROJECT_ROOT_DIST
=
path
.
join
(
NEXT_PROJECT_ROOT
,
'dist'
)
const
NEXT_PROJECT_ROOT_DIST_CLIENT
=
path
.
join
(
NEXT_PROJECT_ROOT_DIST
,
'client'
)
if
(
parseInt
(
React
.
version
)
<
18
)
{
if
(
parseInt
(
React
.
version
)
<
18
)
{
throw
new
Error
(
'Next.js requires react >= 18.2.0 to be installed.'
)
throw
new
Error
(
'Next.js requires react >= 18.2.0 to be installed.'
)
}
}
...
...
packages/next/src/client/components/react-dev-overlay/internal/container/RuntimeError/CallStackFrame.tsx
View file @
5bdf9154
...
@@ -24,10 +24,14 @@ export const CallStackFrame: React.FC<{
...
@@ -24,10 +24,14 @@ export const CallStackFrame: React.FC<{
:
undefined
:
undefined
)
)
// Format method to strip out the webpack layer prefix.
// e.g. (app-pages-browser)/./app/page.tsx -> ./app/page.tsx
const
formattedMethod
=
f
.
methodName
.
replace
(
/^
\([\w
-
]
+
\)\/
/
,
''
)
return
(
return
(
<
div
data
-
nextjs
-
call
-
stack
-
frame
>
<
div
data
-
nextjs
-
call
-
stack
-
frame
>
<
h3
data
-
nextjs
-
frame
-
expanded=
{
Boolean
(
frame
.
expanded
)
}
>
<
h3
data
-
nextjs
-
frame
-
expanded=
{
Boolean
(
frame
.
expanded
)
}
>
<
HotlinkedText
text=
{
f
.
methodName
}
/>
<
HotlinkedText
text=
{
f
ormattedMethod
}
/>
</
h3
>
</
h3
>
<
div
<
div
data
-
has
-
source=
{
hasSource
?
'true'
:
undefined
}
data
-
has
-
source=
{
hasSource
?
'true'
:
undefined
}
...
...
packages/next/src/client/components/react-dev-overlay/internal/helpers/stack-frame.ts
View file @
5bdf9154
import
type
{
StackFrame
}
from
'next/dist/compiled/stacktrace-parser'
import
type
{
StackFrame
}
from
'next/dist/compiled/stacktrace-parser'
import
type
{
OriginalStackFrameResponse
}
from
'../../server/shared'
import
type
{
OriginalStackFrameResponse
}
from
'../../server/shared'
import
{
isWebpackBundled
,
formatFrameSourceFile
}
from
'./webpack-module-path'
export
interface
OriginalStackFrame
extends
OriginalStackFrameResponse
{
export
interface
OriginalStackFrame
extends
OriginalStackFrameResponse
{
error
:
boolean
error
:
boolean
reason
:
string
|
null
reason
:
string
|
null
...
@@ -103,42 +103,6 @@ export function getOriginalStackFrames(
...
@@ -103,42 +103,6 @@ export function getOriginalStackFrames(
)
)
}
}
const
webpackRegExes
=
[
/^
(
rsc:
\/\/
React
\/[^/]
+
\/)?
webpack-internal:
\/\/\/(\.)?(\((\w
+
)\))?
/
,
/^
(
webpack:
\/\/\/(\.)?
|webpack:
\/\/(
_N_E
\/)?)(\((\w
+
)\))?
/
,
]
const
replacementRegExes
=
[
/^
(
rsc:
\/\/
React
\/[^/]
+
\/)
/
,
/^webpack-internal:
\/\/\/(\.)?(\((\w
+
)\))?
/
,
/^
(
webpack:
\/\/\/(\.)?
|webpack:
\/\/(
_N_E
\/)?)(\((\w
+
)\))?
/
,
/
\?\d
+$/
,
// React's fakeFunctionIdx query param
]
function
isWebpackBundled
(
file
:
string
)
{
return
webpackRegExes
.
some
((
regEx
)
=>
regEx
.
test
(
file
))
}
/**
* Format the webpack internal id to original file path
* webpack-internal:///./src/hello.tsx => ./src/hello.tsx
* rsc://React/Server/webpack-internal:///(rsc)/./src/hello.tsx?42 => ./src/hello.tsx
* webpack://_N_E/./src/hello.tsx => ./src/hello.tsx
* webpack://./src/hello.tsx => ./src/hello.tsx
* webpack:///./src/hello.tsx => ./src/hello.tsx
*
* <anonymous> => ''
*/
function
formatFrameSourceFile
(
file
:
string
)
{
if
(
file
===
'<anonymous>'
)
return
''
for
(
const
regex
of
replacementRegExes
)
{
file
=
file
.
replace
(
regex
,
''
)
}
return
file
}
export
function
getFrameSource
(
frame
:
StackFrame
):
string
{
export
function
getFrameSource
(
frame
:
StackFrame
):
string
{
if
(
!
frame
.
file
)
return
''
if
(
!
frame
.
file
)
return
''
...
...
packages/next/src/client/components/react-dev-overlay/internal/helpers/webpack-module-path.test.ts
0 → 100644
View file @
5bdf9154
import
{
formatFrameSourceFile
,
isWebpackBundled
}
from
'./webpack-module-path'
describe
(
'webpack-module-path'
,
()
=>
{
describe
(
'isWebpackBundled'
,
()
=>
{
it
(
'should return true for webpack-internal paths'
,
()
=>
{
expect
(
isWebpackBundled
(
'webpack-internal:///./src/hello.tsx'
)).
toBe
(
true
)
expect
(
isWebpackBundled
(
'rsc://React/Server/webpack-internal:///(rsc)/./src/hello.tsx?42'
)
).
toBe
(
true
)
expect
(
isWebpackBundled
(
'rsc://React/Server/webpack:///(rsc)/./src/hello.tsx?42'
)
).
toBe
(
true
)
expect
(
isWebpackBundled
(
'rsc://React/Server/webpack:///(app-pages-browser)/./src/hello.tsx?42'
)
).
toBe
(
true
)
expect
(
isWebpackBundled
(
'webpack://_N_E/./src/hello.tsx'
)).
toBe
(
true
)
expect
(
isWebpackBundled
(
'webpack://./src/hello.tsx'
)).
toBe
(
true
)
expect
(
isWebpackBundled
(
'webpack:///./src/hello.tsx'
)).
toBe
(
true
)
})
it
(
'should return false for non-webpack-internal paths'
,
()
=>
{
expect
(
isWebpackBundled
(
'<anonymous>'
)).
toBe
(
false
)
expect
(
isWebpackBundled
(
'file:///src/hello.tsx'
)).
toBe
(
false
)
})
})
describe
(
'formatFrameSourceFile'
,
()
=>
{
it
(
'should return the original file path'
,
()
=>
{
expect
(
formatFrameSourceFile
(
'webpack-internal:///./src/hello.tsx'
)).
toBe
(
'./src/hello.tsx'
)
expect
(
formatFrameSourceFile
(
'rsc://React/Server/webpack-internal:///(rsc)/./src/hello.tsx?42'
)
).
toBe
(
'./src/hello.tsx'
)
expect
(
formatFrameSourceFile
(
'rsc://React/Server/webpack:///(rsc)/./src/hello.tsx?42'
)
).
toBe
(
'./src/hello.tsx'
)
expect
(
formatFrameSourceFile
(
'rsc://React/Server/webpack:///(app-pages-browser)/./src/hello.tsx?42'
)
).
toBe
(
'./src/hello.tsx'
)
expect
(
formatFrameSourceFile
(
'webpack://_N_E/./src/hello.tsx'
)).
toBe
(
'./src/hello.tsx'
)
expect
(
formatFrameSourceFile
(
'webpack://./src/hello.tsx'
)).
toBe
(
'./src/hello.tsx'
)
expect
(
formatFrameSourceFile
(
'webpack:///./src/hello.tsx'
)).
toBe
(
'./src/hello.tsx'
)
})
it
(
'should return an empty string for <anonymous> file paths'
,
()
=>
{
expect
(
formatFrameSourceFile
(
'<anonymous>'
)).
toBe
(
''
)
})
})
})
packages/next/src/client/components/react-dev-overlay/internal/helpers/webpack-module-path.ts
0 → 100644
View file @
5bdf9154
const
replacementRegExes
=
[
/^
(
rsc:
\/\/
React
\/[^/]
+
\/)
/
,
/^webpack-internal:
\/\/\/(\([\w
-
]
+
\)\/)?
/
,
/^
(
webpack:
\/\/\/
|webpack:
\/\/(
_N_E
\/)?)(\([\w
-
]
+
\)\/)?
/
,
/
\?\d
+$/
,
// React's fakeFunctionIdx query param
]
export
function
isWebpackBundled
(
file
:
string
)
{
for
(
const
regex
of
replacementRegExes
)
{
if
(
regex
.
test
(
file
))
return
true
file
=
file
.
replace
(
regex
,
''
)
}
return
false
}
/**
* Format the webpack internal id to original file path
* webpack-internal:///./src/hello.tsx => ./src/hello.tsx
* rsc://React/Server/webpack-internal:///(rsc)/./src/hello.tsx?42 => ./src/hello.tsx
* webpack://_N_E/./src/hello.tsx => ./src/hello.tsx
* webpack://./src/hello.tsx => ./src/hello.tsx
* webpack:///./src/hello.tsx => ./src/hello.tsx
*
* <anonymous> => ''
*/
export
function
formatFrameSourceFile
(
file
:
string
)
{
if
(
file
===
'<anonymous>'
)
return
''
for
(
const
regex
of
replacementRegExes
)
{
file
=
file
.
replace
(
regex
,
''
)
}
return
file
}
packages/next/src/client/components/react-dev-overlay/server/middleware.ts
View file @
5bdf9154
...
@@ -13,6 +13,7 @@ import {
...
@@ -13,6 +13,7 @@ import {
noContent
,
noContent
,
type
OriginalStackFrameResponse
,
type
OriginalStackFrameResponse
,
}
from
'./shared'
}
from
'./shared'
import
{
NEXT_PROJECT_ROOT
}
from
'../../../../build/next-dir-paths'
export
{
getServerError
}
from
'../internal/helpers/node-stack-frames'
export
{
getServerError
}
from
'../internal/helpers/node-stack-frames'
export
{
parseStack
}
from
'../internal/helpers/parse-stack'
export
{
parseStack
}
from
'../internal/helpers/parse-stack'
export
{
getSourceMapFromFile
}
export
{
getSourceMapFromFile
}
...
@@ -20,6 +21,7 @@ export { getSourceMapFromFile }
...
@@ -20,6 +21,7 @@ export { getSourceMapFromFile }
import
type
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
type
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
type
webpack
from
'webpack'
import
type
webpack
from
'webpack'
import
type
{
RawSourceMap
}
from
'next/dist/compiled/source-map08'
import
type
{
RawSourceMap
}
from
'next/dist/compiled/source-map08'
import
{
formatFrameSourceFile
}
from
'../internal/helpers/webpack-module-path'
type
Source
=
type
Source
=
|
{
|
{
...
@@ -149,10 +151,12 @@ export async function createOriginalStackFrame({
...
@@ -149,10 +151,12 @@ export async function createOriginalStackFrame({
)
)
)
)
const
resolvedFilePath
=
sourceContent
?
path
.
relative
(
rootDirectory
,
filePath
)
:
sourcePosition
.
source
const
traced
=
{
const
traced
=
{
file
:
sourceContent
file
:
resolvedFilePath
,
?
path
.
relative
(
rootDirectory
,
filePath
)
:
sourcePosition
.
source
,
lineNumber
:
sourcePosition
.
line
,
lineNumber
:
sourcePosition
.
line
,
column
:
(
sourcePosition
.
column
??
0
)
+
1
,
column
:
(
sourcePosition
.
column
??
0
)
+
1
,
methodName
:
methodName
:
...
@@ -286,8 +290,17 @@ export function getOverlayMiddleware(options: {
...
@@ -286,8 +290,17 @@ export function getOverlayMiddleware(options: {
return
badRequest
(
res
)
return
badRequest
(
res
)
}
}
const
formattedFilePath
=
formatFrameSourceFile
(
frame
.
file
)
const
filePath
=
path
.
join
(
rootDirectory
,
formattedFilePath
)
const
isNextjsSource
=
filePath
.
startsWith
(
NEXT_PROJECT_ROOT
)
let
source
:
Source
|
undefined
let
source
:
Source
|
undefined
if
(
isNextjsSource
)
{
sourcePackage
=
'next'
return
json
(
res
,
{
sourcePackage
})
}
try
{
try
{
source
=
await
getSource
(
frame
.
file
,
{
source
=
await
getSource
(
frame
.
file
,
{
distDirectory
,
distDirectory
,
...
...
test/development/acceptance-app/ReactRefreshLogBox.test.ts
View file @
5bdf9154
...
@@ -1288,20 +1288,18 @@ export default function Home() {
...
@@ -1288,20 +1288,18 @@ export default function Home() {
expect
(
stack
).
toMatchInlineSnapshot
(
`
expect
(
stack
).
toMatchInlineSnapshot
(
`
"app/utils.ts (1:7) @ eval
"app/utils.ts (1:7) @ eval
---
---
(app-pages-browser)/
./app/utils.ts
./app/utils.ts
file://TEST_DIR/.next/static/chunks/app/page.js (39:1)
file://TEST_DIR/.next/static/chunks/app/page.js (39:1)
---
---
Next.js
Next.js
---
---
eval
eval
(app-pages-browser)/
./app/page.js
./app/page.js
---
---
(app-pages-browser)/
./app/page.js
./app/page.js
file://TEST_DIR/.next/static/chunks/app/page.js (28:1)
file://TEST_DIR/.next/static/chunks/app/page.js (28:1)
---
---
Next.js
Next.js"
---
React"
`
)
`
)
}
}
...
...
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