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
f3533cb2
Unverified
Commit
f3533cb2
authored
Nov 06, 2024
by
Hendrik Liebau
Committed by
GitHub
Nov 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show readable hook names in stack frames (#72340)
parent
b9dcc6c3
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
176 additions
and
14 deletions
+176
-14
transforms.rs
crates/next-core/src/next_client/transforms.rs
+8
-4
debug_fn_name.rs
crates/next-core/src/next_shared/transforms/debug_fn_name.rs
+34
-0
mod.rs
crates/next-core/src/next_shared/transforms/mod.rs
+1
-0
options.ts
packages/next/src/build/swc/options.ts
+1
-0
error-recovery.test.ts
test/development/acceptance-app/error-recovery.test.ts
+1
-1
error-recovery.test.ts
test/development/acceptance/error-recovery.test.ts
+2
-2
hydration-error.test.ts
test/development/acceptance/hydration-error.test.ts
+6
-6
page.tsx
...velopment/app-dir/hook-function-names/app/button/page.tsx
+19
-0
layout.tsx
test/development/app-dir/hook-function-names/app/layout.tsx
+8
-0
page.tsx
test/development/app-dir/hook-function-names/app/page.tsx
+11
-0
hook-function-names.test.ts
...t/app-dir/hook-function-names/hook-function-names.test.ts
+78
-0
next.config.js
test/development/app-dir/hook-function-names/next.config.js
+6
-0
index.test.js
test/integration/config-devtool-dev/test/index.test.js
+1
-1
No files found.
crates/next-core/src/next_client/transforms.rs
View file @
f3533cb2
...
@@ -8,10 +8,10 @@ use crate::{
...
@@ -8,10 +8,10 @@ use crate::{
next_client
::
context
::
ClientContextType
,
next_client
::
context
::
ClientContextType
,
next_config
::
NextConfig
,
next_config
::
NextConfig
,
next_shared
::
transforms
::{
next_shared
::
transforms
::{
get_next_dynamic_transform_rule
,
get_next_font_transform_rule
,
get_next_image
_rule
,
debug_fn_name
::
get_debug_fn_name_rule
,
get_next_dynamic_transform
_rule
,
get_next_
lint_transform_rule
,
get_next_modularize_imports
_rule
,
get_next_
font_transform_rule
,
get_next_image_rule
,
get_next_lint_transform
_rule
,
get_next_
pages_transforms_rule
,
get_server_actions_transform
_rule
,
get_next_
modularize_imports_rule
,
get_next_pages_transforms
_rule
,
next_amp_attributes
::
get_next_amp_attr_rule
,
get_server_actions_transform_rule
,
next_amp_attributes
::
get_next_amp_attr_rule
,
next_cjs_optimizer
::
get_next_cjs_optimizer_rule
,
next_cjs_optimizer
::
get_next_cjs_optimizer_rule
,
next_disallow_re_export_all_in_page
::
get_next_disallow_export_all_in_page_rule
,
next_disallow_re_export_all_in_page
::
get_next_disallow_export_all_in_page_rule
,
next_page_config
::
get_next_page_config_rule
,
next_page_config
::
get_next_page_config_rule
,
...
@@ -43,6 +43,10 @@ pub async fn get_next_client_transforms_rules(
...
@@ -43,6 +43,10 @@ pub async fn get_next_client_transforms_rules(
rules
.push
(
get_next_font_transform_rule
(
enable_mdx_rs
));
rules
.push
(
get_next_font_transform_rule
(
enable_mdx_rs
));
if
mode
.await
?
.is_development
()
{
rules
.push
(
get_debug_fn_name_rule
(
enable_mdx_rs
));
}
let
mut
is_app_dir
=
false
;
let
mut
is_app_dir
=
false
;
match
context_ty
{
match
context_ty
{
...
...
crates/next-core/src/next_shared/transforms/debug_fn_name.rs
0 → 100644
View file @
f3533cb2
use
anyhow
::
Result
;
use
async_trait
::
async_trait
;
use
next_custom_transforms
::
transforms
::
debug_fn_name
::
debug_fn_name
;
use
swc_core
::
ecma
::{
ast
::
Program
,
visit
::
VisitMutWith
};
use
turbo_tasks
::
Vc
;
use
turbopack
::
module_options
::{
ModuleRule
,
ModuleRuleEffect
};
use
turbopack_ecmascript
::{
CustomTransformer
,
EcmascriptInputTransform
,
TransformContext
};
use
super
::
module_rule_match_js_no_url
;
pub
fn
get_debug_fn_name_rule
(
enable_mdx_rs
:
bool
)
->
ModuleRule
{
let
debug_fn_name_transform
=
EcmascriptInputTransform
::
Plugin
(
Vc
::
cell
(
Box
::
new
(
DebugFnNameTransformer
{})
as
_
));
ModuleRule
::
new
(
module_rule_match_js_no_url
(
enable_mdx_rs
),
vec!
[
ModuleRuleEffect
::
ExtendEcmascriptTransforms
{
prepend
:
Vc
::
cell
(
vec!
[]),
append
:
Vc
::
cell
(
vec!
[
debug_fn_name_transform
]),
}],
)
}
#[derive(Debug)]
struct
DebugFnNameTransformer
{}
#[async_trait]
impl
CustomTransformer
for
DebugFnNameTransformer
{
#[tracing
::
instrument(level
=
tracing
::
Level
::
TRACE,
name
=
"debug_fn_name"
,
skip_all)]
async
fn
transform
(
&
self
,
program
:
&
mut
Program
,
_ctx
:
&
TransformContext
<
'_
>
)
->
Result
<
()
>
{
program
.visit_mut_with
(
&
mut
debug_fn_name
());
Ok
(())
}
}
crates/next-core/src/next_shared/transforms/mod.rs
View file @
f3533cb2
pub
(
crate
)
mod
debug_fn_name
;
pub
(
crate
)
mod
emotion
;
pub
(
crate
)
mod
emotion
;
pub
(
crate
)
mod
modularize_imports
;
pub
(
crate
)
mod
modularize_imports
;
pub
(
crate
)
mod
next_amp_attributes
;
pub
(
crate
)
mod
next_amp_attributes
;
...
...
packages/next/src/build/swc/options.ts
View file @
f3533cb2
...
@@ -219,6 +219,7 @@ function getBaseSWCOptions({
...
@@ -219,6 +219,7 @@ function getBaseSWCOptions({
// On server side of pages router we prefer CJS.
// On server side of pages router we prefer CJS.
preferEsm
:
esm
,
preferEsm
:
esm
,
lintCodemodComments
:
true
,
lintCodemodComments
:
true
,
debugFunctionName
:
development
,
}
}
}
}
...
...
test/development/acceptance-app/error-recovery.test.ts
View file @
f3533cb2
...
@@ -141,7 +141,7 @@ describe.each(['default', 'turbo'])('Error recovery app %s', () => {
...
@@ -141,7 +141,7 @@ describe.each(['default', 'turbo'])('Error recovery app %s', () => {
await
session
.
waitForAndOpenRuntimeError
()
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxSource
()).
toMatchInlineSnapshot
(
`
expect
(
await
session
.
getRedboxSource
()).
toMatchInlineSnapshot
(
`
"index.js (7:11) @
eval
"index.js (7:11) @
Index.useCallback[increment]
5 | const increment = useCallback(() => {
5 | const increment = useCallback(() => {
6 | setCount(c => c + 1)
6 | setCount(c => c + 1)
...
...
test/development/acceptance/error-recovery.test.ts
View file @
f3533cb2
...
@@ -107,7 +107,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
...
@@ -107,7 +107,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
await
session
.
assertHasRedbox
()
await
session
.
assertHasRedbox
()
if
(
isTurbopack
)
{
if
(
isTurbopack
)
{
expect
(
await
session
.
getRedboxSource
()).
toMatchInlineSnapshot
(
`
expect
(
await
session
.
getRedboxSource
()).
toMatchInlineSnapshot
(
`
"index.js (7:11) @
<unknown>
"index.js (7:11) @
Index.useCallback[increment]
5 | const increment = useCallback(() => {
5 | const increment = useCallback(() => {
6 | setCount(c => c + 1)
6 | setCount(c => c + 1)
...
@@ -119,7 +119,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
...
@@ -119,7 +119,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
`
)
`
)
}
else
{
}
else
{
expect
(
await
session
.
getRedboxSource
()).
toMatchInlineSnapshot
(
`
expect
(
await
session
.
getRedboxSource
()).
toMatchInlineSnapshot
(
`
"index.js (7:11) @
eval
"index.js (7:11) @
Index.useCallback[increment]
5 | const increment = useCallback(() => {
5 | const increment = useCallback(() => {
6 | setCount(c => c + 1)
6 | setCount(c => c + 1)
...
...
test/development/acceptance/hydration-error.test.ts
View file @
f3533cb2
...
@@ -127,7 +127,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
...
@@ -127,7 +127,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
<AppContainer>
<AppContainer>
<Container fn={function fn}>
<Container fn={function fn}>
<ReactDevOverlay>
<ReactDevOverlay>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
onError={function}
>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
...
>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<Mismatch>
<Mismatch>
...
@@ -222,7 +222,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
...
@@ -222,7 +222,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
<AppContainer>
<AppContainer>
<Container fn={function fn}>
<Container fn={function fn}>
<ReactDevOverlay>
<ReactDevOverlay>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
onError={function}
>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
...
>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<Mismatch>
<Mismatch>
...
@@ -312,7 +312,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
...
@@ -312,7 +312,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
<AppContainer>
<AppContainer>
<Container fn={function fn}>
<Container fn={function fn}>
<ReactDevOverlay>
<ReactDevOverlay>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
onError={function}
>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
...
>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<Mismatch>
<Mismatch>
...
@@ -388,7 +388,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
...
@@ -388,7 +388,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
<AppContainer>
<AppContainer>
<Container fn={function fn}>
<Container fn={function fn}>
<ReactDevOverlay>
<ReactDevOverlay>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
onError={function}
>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
...
>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<Mismatch>
<Mismatch>
...
@@ -474,7 +474,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
...
@@ -474,7 +474,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
<AppContainer>
<AppContainer>
<Container fn={function fn}>
<Container fn={function fn}>
<ReactDevOverlay>
<ReactDevOverlay>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
onError={function}
>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
...
>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<App pageProps={{}} Component={function Mismatch} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<Mismatch>
<Mismatch>
...
@@ -561,7 +561,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
...
@@ -561,7 +561,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
<AppContainer>
<AppContainer>
<Container fn={function fn}>
<Container fn={function fn}>
<ReactDevOverlay>
<ReactDevOverlay>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
onError={function}
>
<ErrorBoundary globalOverlay={undefined} isMounted={false}
...
>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<PathnameContextProviderAdapter router={{sdc:{},sbc:{}, ...}} isAutoExport={true}>
<App pageProps={{}} Component={function Page} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<App pageProps={{}} Component={function Page} err={undefined} router={{sdc:{},sbc:{}, ...}}>
<Page>
<Page>
...
...
test/development/app-dir/hook-function-names/app/button/page.tsx
0 → 100644
View file @
f3533cb2
'use client'
import
{
useCallback
}
from
'react'
const
Button
=
({
message
}:
{
message
:
string
})
=>
{
const
handleClick
=
useCallback
(()
=>
{
throw
new
Error
(
message
)
},
[
message
])
return
(
<
button
type=
"button"
onClick=
{
handleClick
}
>
Click me
</
button
>
)
}
export
default
function
Page
()
{
return
<
Button
message=
"Kaputt!"
/>
}
test/development/app-dir/hook-function-names/app/layout.tsx
0 → 100644
View file @
f3533cb2
import
{
ReactNode
}
from
'react'
export
default
function
Root
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
html
>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/development/app-dir/hook-function-names/app/page.tsx
0 → 100644
View file @
f3533cb2
'use client'
import
{
useEffect
}
from
'react'
export
default
function
Page
()
{
useEffect
(()
=>
{
throw
new
Error
(
'error in useEffect'
)
},
[])
return
<
p
>
Hello world!
</
p
>
}
test/development/app-dir/hook-function-names/hook-function-names.test.ts
0 → 100644
View file @
f3533cb2
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
assertHasRedbox
,
getRedboxSource
,
waitForAndOpenRuntimeError
,
}
from
'next-test-utils'
describe
(
'hook-function-names'
,
()
=>
{
const
{
next
,
isTurbopack
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should show readable hook names in stacks'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/button'
)
await
browser
.
elementByCss
(
'button'
).
click
()
await
waitForAndOpenRuntimeError
(
browser
)
if
(
isTurbopack
)
{
expect
(
await
getRedboxSource
(
browser
)).
toMatchInlineSnapshot
(
`
"app/button/page.tsx (7:11) @ Button.useCallback[handleClick]
5 | const Button = ({ message }: { message: string }) => {
6 | const handleClick = useCallback(() => {
> 7 | throw new Error(message)
| ^
8 | }, [message])
9 |
10 | return ("
`
)
}
else
{
expect
(
await
getRedboxSource
(
browser
)).
toMatchInlineSnapshot
(
`
"app/button/page.tsx (7:11) @ Button.useCallback[handleClick]
5 | const Button = ({ message }: { message: string }) => {
6 | const handleClick = useCallback(() => {
> 7 | throw new Error(message)
| ^
8 | }, [message])
9 |
10 | return ("
`
)
}
})
it
(
'should show readable hook names in stacks for default-exported components'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
await
assertHasRedbox
(
browser
)
if
(
isTurbopack
)
{
expect
(
await
getRedboxSource
(
browser
)).
toMatchInlineSnapshot
(
`
"app/page.tsx (7:11) @ Page.useEffect
5 | export default function Page() {
6 | useEffect(() => {
> 7 | throw new Error('error in useEffect')
| ^
8 | }, [])
9 |
10 | return <p>Hello world!</p>"
`
)
}
else
{
expect
(
await
getRedboxSource
(
browser
)).
toMatchInlineSnapshot
(
`
"app/page.tsx (7:11) @ Page.useEffect
5 | export default function Page() {
6 | useEffect(() => {
> 7 | throw new Error('error in useEffect')
| ^
8 | }, [])
9 |
10 | return <p>Hello world!</p>"
`
)
}
})
})
test/development/app-dir/hook-function-names/next.config.js
0 → 100644
View file @
f3533cb2
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{}
module
.
exports
=
nextConfig
test/integration/config-devtool-dev/test/index.test.js
View file @
f3533cb2
...
@@ -38,7 +38,7 @@ const appDir = join(__dirname, '../')
...
@@ -38,7 +38,7 @@ const appDir = join(__dirname, '../')
// TODO: add win32 snapshot
// TODO: add win32 snapshot
}
else
{
}
else
{
expect
(
await
getRedboxSource
(
browser
)).
toMatchInlineSnapshot
(
`
expect
(
await
getRedboxSource
(
browser
)).
toMatchInlineSnapshot
(
`
"pages/index.js (5:11) @
eval
"pages/index.js (5:11) @
Index.useEffect
3 | export default function Index(props) {
3 | export default function Index(props) {
4 | useEffect(() => {
4 | useEffect(() => {
...
...
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