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
5ac2327e
Unverified
Commit
5ac2327e
authored
Aug 19, 2026
by
Niklas Mischkulnig
Committed by
GitHub
Aug 19, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[16.3] Turbopack: retain conditions when replacing resolve request keys (#97453)
Backports #97372
parent
0ccb3e7f
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
84 additions
and
11 deletions
+84
-11
next-server-nft.test.ts
test/production/next-server-nft/next-server-nft.test.ts
+1
-0
mod.rs
turbopack/crates/turbopack-core/src/resolve/mod.rs
+7
-11
.gitignore
...crates/turbopack-tracing/tests/node-file-trace/.gitignore
+3
-0
input.js
...st/unit/module-sync-condition-cjs-nested-symlink/input.js
+2
-0
helper.cjs
.../helpers@1.0.0/node_modules/@scope/helpers/cjs/helper.cjs
+1
-0
helper.js
...e/helpers@1.0.0/node_modules/@scope/helpers/esm/helper.js
+1
-0
package.json
...re/helpers@1.0.0/node_modules/@scope/helpers/package.json
+13
-0
helpers
...d-symlink/node_modules/.store/node_modules/@scope/helpers
+1
-0
helpers
...node_modules/.store/pkg@1.0.0/node_modules/@scope/helpers
+1
-0
index.js
...k/node_modules/.store/pkg@1.0.0/node_modules/pkg/index.js
+2
-0
package.json
...de_modules/.store/pkg@1.0.0/node_modules/pkg/package.json
+5
-0
pkg
...module-sync-condition-cjs-nested-symlink/node_modules/pkg
+1
-0
output.js
...t/unit/module-sync-condition-cjs-nested-symlink/output.js
+14
-0
helper.cjs
...est/unit/module-sync-condition-cjs-subpath/cjs/helper.cjs
+1
-0
helper.mjs
...est/unit/module-sync-condition-cjs-subpath/esm/helper.mjs
+1
-0
input.js
...race/test/unit/module-sync-condition-cjs-subpath/input.js
+2
-0
output.js
...ace/test/unit/module-sync-condition-cjs-subpath/output.js
+10
-0
package.json
.../test/unit/module-sync-condition-cjs-subpath/package.json
+12
-0
unit.rs
turbopack/crates/turbopack-tracing/tests/unit.rs
+6
-0
No files found.
test/production/next-server-nft/next-server-nft.test.ts
View file @
5ac2327e
...
@@ -627,6 +627,7 @@ async function readNormalizedNFT(next, name) {
...
@@ -627,6 +627,7 @@ async function readNormalizedNFT(next, name) {
"./.next/server/server-reference-manifest.js",
"./.next/server/server-reference-manifest.js",
"./.next/server/server-reference-manifest.json",
"./.next/server/server-reference-manifest.json",
"/node_modules/@swc/helpers/cjs/_interop_require_default.cjs",
"/node_modules/@swc/helpers/cjs/_interop_require_default.cjs",
"/node_modules/@swc/helpers/esm/_interop_require_default.js",
"/node_modules/next/dist/build/adapter/setup-node-env.external.js",
"/node_modules/next/dist/build/adapter/setup-node-env.external.js",
"/node_modules/next/dist/client/components/hooks-server-context.js",
"/node_modules/next/dist/client/components/hooks-server-context.js",
"/node_modules/next/dist/client/components/static-generation-bailout.js",
"/node_modules/next/dist/client/components/static-generation-bailout.js",
...
...
turbopack/crates/turbopack-core/src/resolve/mod.rs
View file @
5ac2327e
...
@@ -974,7 +974,7 @@ impl ResolveResult {
...
@@ -974,7 +974,7 @@ impl ResolveResult {
fn
with_replaced_request_key
(
fn
with_replaced_request_key
(
&
self
,
&
self
,
old_request_key
:
RcStr
,
old_request_key
:
RcStr
,
request_key
:
RequestKey
,
new_request_key
:
RcStr
,
)
->
Result
<
Vc
<
Self
>>
{
)
->
Result
<
Vc
<
Self
>>
{
let
new_primary
=
self
let
new_primary
=
self
.primary
.primary
...
@@ -983,11 +983,8 @@ impl ResolveResult {
...
@@ -983,11 +983,8 @@ impl ResolveResult {
let
remaining
=
k
.request
.as_ref
()
?
.strip_prefix
(
&*
old_request_key
)
?
;
let
remaining
=
k
.request
.as_ref
()
?
.strip_prefix
(
&*
old_request_key
)
?
;
Some
((
Some
((
RequestKey
{
RequestKey
{
request
:
request_key
request
:
Some
(
format!
(
"{new_request_key}{remaining}"
)
.into
()),
.request
conditions
:
k
.conditions
.clone
(),
.as_ref
()
.map
(|
r
|
format!
(
"{r}{remaining}"
)
.into
()),
conditions
:
request_key
.conditions
.clone
(),
},
},
v
.clone
(),
v
.clone
(),
))
))
...
@@ -2665,12 +2662,11 @@ async fn apply_in_package(
...
@@ -2665,12 +2662,11 @@ async fn apply_in_package(
};
};
let
refs
=
refs
.clone
();
let
refs
=
refs
.clone
();
let
request_key
=
RequestKey
::
new
(
request
.clone
());
if
value
.as_bool
()
==
Some
(
false
)
{
if
value
.as_bool
()
==
Some
(
false
)
{
return
Ok
(
Some
(
ResolveResultOrCell
::
Value
(
return
Ok
(
Some
(
ResolveResultOrCell
::
Value
(
ResolveResult
::
primary_with_affecting_sources
(
ResolveResult
::
primary_with_affecting_sources
(
request_key
,
RequestKey
::
new
(
request
.clone
())
,
ResolveResultItem
::
Ignore
,
ResolveResultItem
::
Ignore
,
refs
,
refs
,
),
),
...
@@ -2689,7 +2685,7 @@ async fn apply_in_package(
...
@@ -2689,7 +2685,7 @@ async fn apply_in_package(
.with_fragment
(
fragment
.clone
()),
.with_fragment
(
fragment
.clone
()),
options
,
options
,
)
)
.with_replaced_request_key
(
value
.into
(),
request
_key
);
.with_replaced_request_key
(
value
.into
(),
request
.clone
()
);
if
options_value
.collect_affecting_sources
&&
!
refs
.is_empty
()
{
if
options_value
.collect_affecting_sources
&&
!
refs
.is_empty
()
{
result
=
result
.with_affecting_sources
(
refs
.into_iter
()
.map
(|
src
|
*
src
)
.collect
());
result
=
result
.with_affecting_sources
(
refs
.into_iter
()
.map
(|
src
|
*
src
)
.collect
());
}
}
...
@@ -2831,7 +2827,7 @@ async fn resolve_module_request(
...
@@ -2831,7 +2827,7 @@ async fn resolve_module_request(
fragment
.clone
(),
fragment
.clone
(),
options
,
options
,
)
)
.with_replaced_request_key
(
rcstr!
(
"."
),
RequestKey
::
new
(
name
.clone
()
)),
.with_replaced_request_key
(
rcstr!
(
"."
),
name
.clone
(
)),
);
);
}
}
FindPackageItem
::
PackageFile
{
name
,
file
}
=>
{
FindPackageItem
::
PackageFile
{
name
,
file
}
=>
{
...
@@ -2848,7 +2844,7 @@ async fn resolve_module_request(
...
@@ -2848,7 +2844,7 @@ async fn resolve_module_request(
)
)
.await
?
.await
?
.into_cell
()
.into_cell
()
.with_replaced_request_key
(
rcstr!
(
"."
),
RequestKey
::
new
(
name
.clone
()
));
.with_replaced_request_key
(
rcstr!
(
"."
),
name
.clone
(
));
results
.push
(
resolved_result
)
results
.push
(
resolved_result
)
}
}
}
}
...
...
turbopack/crates/turbopack-tracing/tests/node-file-trace/.gitignore
View file @
5ac2327e
...
@@ -4,3 +4,6 @@ integration/**/dist
...
@@ -4,3 +4,6 @@ integration/**/dist
!integration/**/node_modules
!integration/**/node_modules
!integration/**/.pnpm
!integration/**/.pnpm
# Some unit cases need a checked-in node_modules to model a package layout
!test/unit/**/node_modules
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/input.js
0 → 100644
View file @
5ac2327e
const
{
test
}
=
require
(
'pkg'
)
console
.
log
(
test
)
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/helpers@1.0.0/node_modules/@scope/helpers/cjs/helper.cjs
0 → 100644
View file @
5ac2327e
exports.test = 'fallback version'
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/helpers@1.0.0/node_modules/@scope/helpers/esm/helper.js
0 → 100644
View file @
5ac2327e
export
const
test
=
'module-sync version'
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/helpers@1.0.0/node_modules/@scope/helpers/package.json
0 → 100644
View file @
5ac2327e
{
"name"
:
"@scope/helpers"
,
"version"
:
"1.0.0"
,
"type"
:
"module"
,
"exports"
:
{
"./_/helper"
:
{
"module-sync"
:
"./esm/helper.js"
,
"webpack"
:
"./esm/helper.js"
,
"import"
:
"./esm/helper.js"
,
"default"
:
"./cjs/helper.cjs"
}
}
}
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/node_modules/@scope/helpers
0 → 120000
View file @
5ac2327e
../../helpers@1.0.0/node_modules/@scope/helpers
\ No newline at end of file
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/pkg@1.0.0/node_modules/@scope/helpers
0 → 120000
View file @
5ac2327e
../../../helpers@1.0.0/node_modules/@scope/helpers
\ No newline at end of file
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/pkg@1.0.0/node_modules/pkg/index.js
0 → 100644
View file @
5ac2327e
const
{
test
}
=
require
(
'@scope/helpers/_/helper'
)
module
.
exports
=
{
test
}
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/pkg@1.0.0/node_modules/pkg/package.json
0 → 100644
View file @
5ac2327e
{
"name"
:
"pkg"
,
"version"
:
"1.0.0"
,
"main"
:
"index.js"
}
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/node_modules/pkg
0 → 120000
View file @
5ac2327e
.store/pkg@1.0.0/node_modules/pkg
\ No newline at end of file
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-nested-symlink/output.js
0 → 100644
View file @
5ac2327e
;[
// The `@scope/helpers` package is reachable through two `node_modules` directories (as in a pnpm
// install, where the virtual store hoists every package into `node_modules/.pnpm/node_modules`).
// Resolving the same request in more than one directory must not drop the alternatives a single
// directory resolved to: both the `module-sync` target (picked by `require()` on Node >= 22.12)
// and the `default` target (picked by older Node versions) have to be traced.
'package.json'
,
'test/unit/module-sync-condition-cjs-nested-symlink/input.js'
,
'test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/helpers@1.0.0/node_modules/@scope/helpers/cjs/helper.cjs'
,
'test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/helpers@1.0.0/node_modules/@scope/helpers/esm/helper.js'
,
'test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/helpers@1.0.0/node_modules/@scope/helpers/package.json'
,
'test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/pkg@1.0.0/node_modules/pkg/index.js'
,
'test/unit/module-sync-condition-cjs-nested-symlink/node_modules/.store/pkg@1.0.0/node_modules/pkg/package.json'
,
]
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-subpath/cjs/helper.cjs
0 → 100644
View file @
5ac2327e
exports.test = 'fallback version'
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-subpath/esm/helper.mjs
0 → 100644
View file @
5ac2327e
export
const
test
=
'module-sync version'
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-subpath/input.js
0 → 100644
View file @
5ac2327e
const
{
test
}
=
require
(
'test-pkg-sync-cjs-subpath/_/helper'
)
console
.
log
(
test
)
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-subpath/output.js
0 → 100644
View file @
5ac2327e
;[
// A CommonJS `require()` of a subpath export whose conditions are ordered `module-sync`,
// `webpack`, `import`, `default` - the shape published packages use to hand an ESM file to
// `require()` on Node >= 22.12 and a CommonJS file to older Node versions. Both targets have to be
// traced, because which one the runtime picks depends on its Node version.
'test/unit/module-sync-condition-cjs-subpath/cjs/helper.cjs'
,
'test/unit/module-sync-condition-cjs-subpath/esm/helper.mjs'
,
'test/unit/module-sync-condition-cjs-subpath/input.js'
,
'test/unit/module-sync-condition-cjs-subpath/package.json'
,
]
turbopack/crates/turbopack-tracing/tests/node-file-trace/test/unit/module-sync-condition-cjs-subpath/package.json
0 → 100644
View file @
5ac2327e
{
"name"
:
"test-pkg-sync-cjs-subpath"
,
"type"
:
"commonjs"
,
"exports"
:
{
"./_/helper"
:
{
"module-sync"
:
"./esm/helper.mjs"
,
"webpack"
:
"./esm/helper.mjs"
,
"import"
:
"./esm/helper.mjs"
,
"default"
:
"./cjs/helper.cjs"
}
}
}
turbopack/crates/turbopack-tracing/tests/unit.rs
View file @
5ac2327e
...
@@ -126,6 +126,12 @@ static ALLOC: turbo_tasks_malloc::TurboMalloc = turbo_tasks_malloc::TurboMalloc;
...
@@ -126,6 +126,12 @@ static ALLOC: turbo_tasks_malloc::TurboMalloc = turbo_tasks_malloc::TurboMalloc;
#[case
::
module_sync_condition_cjs(
"module-sync-condition-cjs"
)]
#[case
::
module_sync_condition_cjs(
"module-sync-condition-cjs"
)]
// Turbopack always includes the module-sync version, regardless of the current Node version
// Turbopack always includes the module-sync version, regardless of the current Node version
// #[case::module_sync_condition_cjs_node20("module-sync-condition-cjs-node20")]
// #[case::module_sync_condition_cjs_node20("module-sync-condition-cjs-node20")]
// A `require()` of a subpath export that hands the `module-sync` condition an ESM file and
// `default` a CommonJS one (not a case that any of the above cover): both have to be traced.
#[case
::
module_sync_condition_cjs_subpath(
"module-sync-condition-cjs-subpath"
)]
// The same, but with the package reachable through two `node_modules` directories, as in a pnpm
// install: merging the results of both must not drop either target.
#[case
::
module_sync_condition_cjs_nested_symlink(
"module-sync-condition-cjs-nested-symlink"
)]
#[case
::
module_sync_condition_es(
"module-sync-condition-es"
)]
#[case
::
module_sync_condition_es(
"module-sync-condition-es"
)]
#[case
::
module_sync_condition_es_nested(
"module-sync-condition-es-nested"
)]
#[case
::
module_sync_condition_es_nested(
"module-sync-condition-es-nested"
)]
// Turbopack always includes the module-sync version, regardless of the current Node version
// Turbopack always includes the module-sync version, regardless of the current Node version
...
...
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