Skip to content

[Turbopack] name the module factory function in dev mode #73553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ impl Project {
} else {
SourceMapsType::None
})
.use_annotated_stack_traces()
.build(),
);

Expand Down
5 changes: 4 additions & 1 deletion crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,10 @@ pub async fn get_client_chunking_context(
.module_id_strategy(module_id_strategy);

if next_mode.is_development() {
builder = builder.hot_module_replacement().use_file_source_map_uris();
builder = builder
.hot_module_replacement()
.use_file_source_map_uris()
.use_annotated_stack_traces();
} else {
builder = builder.chunking_config(
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
Expand Down
8 changes: 6 additions & 2 deletions crates/next-core/src/next_edge/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ pub async fn get_edge_chunking_context_with_client_assets(
})
.module_id_strategy(module_id_strategy);

if !next_mode.is_development() {
if next_mode.is_development() {
builder = builder.use_annotated_stack_traces();
} else {
builder = builder.chunking_config(
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
ChunkingConfig {
Expand Down Expand Up @@ -317,7 +319,9 @@ pub async fn get_edge_chunking_context(
})
.module_id_strategy(module_id_strategy);

if !next_mode.is_development() {
if next_mode.is_development() {
builder = builder.use_annotated_stack_traces();
} else {
builder = builder.chunking_config(
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
ChunkingConfig {
Expand Down
8 changes: 6 additions & 2 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,9 @@ pub async fn get_server_chunking_context_with_client_assets(
.file_tracing(next_mode.is_production());

if next_mode.is_development() {
builder = builder.use_file_source_map_uris();
builder = builder
.use_file_source_map_uris()
.use_annotated_stack_traces();
} else {
builder = builder.chunking_config(
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
Expand Down Expand Up @@ -1095,7 +1097,9 @@ pub async fn get_server_chunking_context(
.file_tracing(next_mode.is_production());

if next_mode.is_development() {
builder = builder.use_file_source_map_uris()
builder = builder
.use_file_source_map_uris()
.use_annotated_stack_traces();
} else {
builder = builder.chunking_config(
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
Expand Down
138 changes: 103 additions & 35 deletions test/development/acceptance-app/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ describe('ReactRefreshLogBox app', () => {
"description": "Error: no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ [project]/index.js [app-client] (ecmascript)
"source": "index.js (3:7) @ Module.
{module evaluation}
> 3 | throw new Error('no')
| ^",
"stack": [
"[project]/index.js [app-client] (ecmascript) index.js (3:7)",
"[project]/app/page.js [app-client] (ecmascript) app/page.js (2:1)",
"Module. {module evaluation} index.js (3:7)",
"Module. {module evaluation} app/page.js (2:1)",
],
}
`)
Expand Down Expand Up @@ -949,26 +950,46 @@ describe('ReactRefreshLogBox app', () => {
)

if (isTurbopack) {
// Set.forEach: https://linear.app/vercel/issue/NDX-554/
// <FIXME-file-protocol>: https://linear.app/vercel/issue/NDX-920/
await expect(browser).toDisplayRedbox(`
{
"description": "Error: test",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:11) @
{default export}
> 3 | throw new Error('test')
| ^",
"stack": [
"{default export} index.js (3:11)",
"Set.forEach <anonymous> (0:0)",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"Page app/page.js (2:1)",
],
}
`)
try {
await expect(browser).toDisplayRedbox(`
{
"description": "Error: test",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:11) @
{default export}
> 3 | throw new Error('test')
| ^",
"stack": [
"{default export} index.js (3:11)",
"Set.forEach <anonymous> (0:0)",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"Page app/page.js (2:1)",
],
}
`)
} catch {
// TODO this is a bug in Turbopack. Stack trace and source map are not matching.
// The stack trace references the bundle before the change to index.js,
// but we look up sourcemap for the bundle after the change to index.js.
// This leads to incorrect line numbers in the stack trace.
await expect(browser).toDisplayRedbox(`
{
"description": "Error: test",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:11) @
{default export}
> 3 | throw new Error('test')
| ^",
"stack": [
"{default export} index.js (3:11)",
"Page app/page.js (2:1)",
],
}
`)
}
} else {
await expect(browser).toDisplayRedbox(`
{
Expand Down Expand Up @@ -1319,17 +1340,63 @@ describe('ReactRefreshLogBox app', () => {
)

await expect(browser).toDisplayRedbox(`
{
"description": "Error: Server component error!",
"environmentLabel": "Server",
"label": "Runtime Error",
"source": "app/page.js (2:9) @ Page
[
{
"description": "Error: Server component error!",
"environmentLabel": "Server",
"label": "Runtime Error",
"source": "app/page.js (2:9) @ Page
> 2 | throw new Error('Server component error!')
| ^",
"stack": [
"Page app/page.js (2:9)",
],
}
"stack": [
"Page app/page.js (2:9)",
],
},
{
"description": "Error: Server component error!",
"environmentLabel": "Server",
"label": "Runtime Error",
"source": "app/page.js (2:9) @ Page
> 2 | throw new Error('Server component error!')
| ^",
"stack": [
"Page app/page.js (2:9)",
],
},
{
"description": "Error: Server component error!",
"environmentLabel": "Server",
"label": "Runtime Error",
"source": "app/page.js (2:9) @ Page
> 2 | throw new Error('Server component error!')
| ^",
"stack": [
"Page app/page.js (2:9)",
],
},
{
"description": "Error: Server component error!",
"environmentLabel": "Server",
"label": "Runtime Error",
"source": "app/page.js (2:9) @ Page
> 2 | throw new Error('Server component error!')
| ^",
"stack": [
"Page app/page.js (2:9)",
],
},
{
"description": "Error: Server component error!",
"environmentLabel": "Server",
"label": "Runtime Error",
"source": "app/page.js (2:9) @ Page
> 2 | throw new Error('Server component error!')
| ^",
"stack": [
"Page app/page.js (2:9)",
],
},
]
`)
})

Expand Down Expand Up @@ -1612,12 +1679,13 @@ export default function Home() {
"description": "Error: utils error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/utils.ts (1:7) @ [project]/app/utils.ts [app-client] (ecmascript)
"source": "app/utils.ts (1:7) @ Module.
{module evaluation}
> 1 | throw new Error('utils error')
| ^",
"stack": [
"[project]/app/utils.ts [app-client] (ecmascript) app/utils.ts (1:7)",
"[project]/app/page.js [app-client] (ecmascript) app/page.js (2:1)",
"Module. {module evaluation} app/utils.ts (1:7)",
"Module. {module evaluation} app/page.js (2:1)",
],
}
`)
Expand Down
18 changes: 10 additions & 8 deletions test/development/acceptance/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ describe('ReactRefreshLogBox', () => {
"description": "Error: no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ [project]/index.js [ssr] (ecmascript)
"source": "index.js (3:7) @ Module.
{module evaluation}
> 3 | throw new Error('no')
| ^",
"stack": [
"[project]/index.js [ssr] (ecmascript) index.js (3:7)",
"[project]/pages/index.js [ssr] (ecmascript) <module evaluation> pages/index.js (1:1)",
"[project]/pages/index.js [ssr] (ecmascript) pages/index.js (1:1)",
"Module. {module evaluation} index.js (3:7)",
"Module. {module evaluation} pages/index.js (1:1)",
"Module. {module evaluation} pages/index.js (1:1)",
"<FIXME-next-dist-dir>",
],
}
Expand Down Expand Up @@ -170,13 +171,14 @@ describe('ReactRefreshLogBox', () => {
"description": "Error: no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ [project]/index.js [ssr] (ecmascript)
"source": "index.js (3:7) @ Module.
{module evaluation}
> 3 | throw new Error('no')
| ^",
"stack": [
"[project]/index.js [ssr] (ecmascript) index.js (3:7)",
"[project]/pages/index.js [ssr] (ecmascript) <module evaluation> pages/index.js (1:1)",
"[project]/pages/index.js [ssr] (ecmascript) pages/index.js (1:1)",
"Module. {module evaluation} index.js (3:7)",
"Module. {module evaluation} pages/index.js (1:1)",
"Module. {module evaluation} pages/index.js (1:1)",
"<FIXME-next-dist-dir>",
],
}
Expand Down
Loading
Loading