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
d372f051
Commit
d372f051
authored
Jan 27, 2026
by
Luke Sandberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert
7b2c80e2
... trying again
parent
59db275d
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
275 additions
and
120 deletions
+275
-120
app.rs
crates/next-api/src/app.rs
+0
-4
dynamic_imports.rs
crates/next-api/src/dynamic_imports.rs
+35
-22
pages.rs
crates/next-api/src/pages.rs
+12
-17
app_client_references_chunks.rs
...es/next-core/src/next_app/app_client_references_chunks.rs
+1
-1
FeatureCard.tsx
...ment/nested-dynamic-components/components/FeatureCard.tsx
+23
-0
UserProfile.tsx
...ment/nested-dynamic-components/components/UserProfile.tsx
+20
-0
NestedBadge.tsx
...sted-dynamic-components/components/nested/NestedBadge.tsx
+3
-0
NestedIcon.tsx
...ested-dynamic-components/components/nested/NestedIcon.tsx
+3
-0
NestedStats.tsx
...sted-dynamic-components/components/nested/NestedStats.tsx
+3
-0
nested-dynamic-components.test.ts
...sted-dynamic-components/nested-dynamic-components.test.ts
+58
-0
index.tsx
test/development/nested-dynamic-components/pages/index.tsx
+22
-0
chunking_context.rs
turbopack/crates/turbopack-browser/src/chunking_context.rs
+11
-23
chunk_group.rs
turbopack/crates/turbopack-core/src/chunk/chunk_group.rs
+34
-9
chunking_context.rs
...opack/crates/turbopack-core/src/chunk/chunking_context.rs
+39
-24
chunking_context.rs
turbopack/crates/turbopack-nodejs/src/chunking_context.rs
+11
-20
No files found.
crates/next-api/src/app.rs
View file @
d372f051
...
@@ -1566,8 +1566,6 @@ impl AppEndpoint {
...
@@ -1566,8 +1566,6 @@ impl AppEndpoint {
if
emit_manifests
==
EmitManifests
::
Full
{
if
emit_manifests
==
EmitManifests
::
Full
{
let
dynamic_import_entries
=
collect_next_dynamic_chunks
(
let
dynamic_import_entries
=
collect_next_dynamic_chunks
(
*
module_graphs
.full
,
*
client_chunking_context
,
next_dynamic_imports
,
next_dynamic_imports
,
NextDynamicChunkAvailability
::
ClientReferences
(
NextDynamicChunkAvailability
::
ClientReferences
(
&*
(
client_references_chunks
.await
?
),
&*
(
client_references_chunks
.await
?
),
...
@@ -1682,8 +1680,6 @@ impl AppEndpoint {
...
@@ -1682,8 +1680,6 @@ impl AppEndpoint {
let
loadable_manifest_output
=
if
emit_manifests
==
EmitManifests
::
Full
{
let
loadable_manifest_output
=
if
emit_manifests
==
EmitManifests
::
Full
{
// create react-loadable-manifest for next/dynamic
// create react-loadable-manifest for next/dynamic
let
dynamic_import_entries
=
collect_next_dynamic_chunks
(
let
dynamic_import_entries
=
collect_next_dynamic_chunks
(
*
module_graphs
.full
,
*
client_chunking_context
,
next_dynamic_imports
,
next_dynamic_imports
,
NextDynamicChunkAvailability
::
ClientReferences
(
NextDynamicChunkAvailability
::
ClientReferences
(
&*
(
client_references_chunks
.await
?
),
&*
(
client_references_chunks
.await
?
),
...
...
crates/next-api/src/dynamic_imports.rs
View file @
d372f051
...
@@ -30,24 +30,29 @@ use turbo_tasks::{
...
@@ -30,24 +30,29 @@ use turbo_tasks::{
debug
::
ValueDebugFormat
,
trace
::
TraceRawVcs
,
debug
::
ValueDebugFormat
,
trace
::
TraceRawVcs
,
};
};
use
turbopack_core
::{
use
turbopack_core
::{
chunk
::{
Chunk
ableModule
,
ChunkingContext
,
availability_info
::
AvailabilityInfo
},
chunk
::{
Chunk
GroupResult
,
ChunkableModule
},
module
::
Module
,
module
::
Module
,
module_graph
::
{
ModuleGraph
,
ModuleGraphLayer
}
,
module_graph
::
ModuleGraphLayer
,
output
::{
OutputAssetsReference
,
OutputAssetsWithReferenced
},
output
::{
OutputAssetsReference
,
OutputAssetsWithReferenced
},
};
};
use
crate
::
module_graph
::
DynamicImportEntriesWithImporter
;
use
crate
::
module_graph
::
DynamicImportEntriesWithImporter
;
pub
(
crate
)
enum
NextDynamicChunkAvailability
<
'a
>
{
pub
(
crate
)
enum
NextDynamicChunkAvailability
<
'a
>
{
/// In App Router, the client references
/// In App Router, the client references
chunks contain the async loaders
ClientReferences
(
&
'a
ClientReferencesChunks
),
ClientReferences
(
&
'a
ClientReferencesChunks
),
/// In Pages Router, the base page chunk group
/// In Pages Router, the base page chunk group
result
AvailabilityInfo
(
AvailabilityInfo
),
PageChunkGroup
(
&
'a
ChunkGroupResult
),
}
}
/// Collects the chunk outputs for next/dynamic imports by looking up pre-computed
/// async loaders from the chunk group results.
///
/// This function no longer recomputes chunks - instead it looks up the async loader
/// outputs that were already computed by `make_chunk_group` when the parent chunk
/// groups were created. This ensures consistency between the manifest and the actual
/// chunks served at runtime.
pub
(
crate
)
async
fn
collect_next_dynamic_chunks
(
pub
(
crate
)
async
fn
collect_next_dynamic_chunks
(
module_graph
:
Vc
<
ModuleGraph
>
,
chunking_context
:
Vc
<
Box
<
dyn
ChunkingContext
>>
,
dynamic_import_entries
:
ReadRef
<
DynamicImportEntriesWithImporter
>
,
dynamic_import_entries
:
ReadRef
<
DynamicImportEntriesWithImporter
>
,
chunking_availability
:
NextDynamicChunkAvailability
<
'_
>
,
chunking_availability
:
NextDynamicChunkAvailability
<
'_
>
,
)
->
Result
<
ResolvedVc
<
DynamicImportedChunks
>>
{
)
->
Result
<
ResolvedVc
<
DynamicImportedChunks
>>
{
...
@@ -57,28 +62,36 @@ pub(crate) async fn collect_next_dynamic_chunks(
...
@@ -57,28 +62,36 @@ pub(crate) async fn collect_next_dynamic_chunks(
.map
(|(
dynamic_entry
,
parent_client_reference
)|
async
move
{
.map
(|(
dynamic_entry
,
parent_client_reference
)|
async
move
{
let
module
=
ResolvedVc
::
upcast
::
<
Box
<
dyn
ChunkableModule
>>
(
*
dynamic_entry
);
let
module
=
ResolvedVc
::
upcast
::
<
Box
<
dyn
ChunkableModule
>>
(
*
dynamic_entry
);
// This is the availability info for the parent chunk group, i.e. the client reference
// Look up the pre-computed async loader from the parent chunk group
// containing the next/dynamic imports
let
async_loader
=
match
chunking_availability
{
let
availability_info
=
match
chunking_availability
{
NextDynamicChunkAvailability
::
ClientReferences
(
client_reference_chunks
)
=>
{
NextDynamicChunkAvailability
::
ClientReferences
(
client_reference_chunks
)
=>
{
client_reference_chunks
// For App Router: look up the chunk group for the parent client reference,
// then find the async loader for this dynamic entry
let
parent_ref
=
parent_client_reference
.context
(
"Parent client reference not found for next/dynamic import"
)
?
;
let
chunk_group
=
client_reference_chunks
.client_component_client_chunks
.client_component_client_chunks
.get
(
.get
(
&
parent_ref
)
&
parent_client_reference
.context
(
"Parent client reference not found for next/dynamic import"
,
)
?
,
)
.context
(
"Client reference chunk group not found for next/dynamic import"
)
?
.context
(
"Client reference chunk group not found for next/dynamic import"
)
?
.await
?
.await
?
;
.availability_info
// Copy the ResolvedVc out of the map to avoid lifetime issues
*
chunk_group
.async_loaders_by_module
.get
(
&
module
)
.context
(
"Dynamic entry not found in async loaders - this may indicate the dynamic
\
import is not reachable from the client reference"
,
)
?
}
}
NextDynamicChunkAvailability
::
AvailabilityInfo
(
availability_info
)
=>
{
NextDynamicChunkAvailability
::
PageChunkGroup
(
chunk_group
)
=>
{
*
availability_info
// For Pages Router: look up directly in the page's chunk group
// Copy the ResolvedVc out of the map to avoid lifetime issues
*
chunk_group
.async_loaders_by_module
.get
(
&
module
)
.context
(
"Dynamic entry not found in async loaders - this may indicate the dynamic
\
import is not reachable from the page entry"
,
)
?
}
}
};
};
let
async_loader
=
// Get the output assets from the async loader reference
chunking_context
.async_loader_chunk_item
(
*
module
,
module_graph
,
availability_info
);
// Upcast to OutputAssetsReference to call references()
let
async_chunk_group
=
async_loader
.references
()
.to_resolved
()
.await
?
;
let
async_chunk_group
=
async_loader
.references
()
.to_resolved
()
.await
?
;
Ok
((
*
dynamic_entry
,
(
*
dynamic_entry
,
async_chunk_group
)))
Ok
((
*
dynamic_entry
,
(
*
dynamic_entry
,
async_chunk_group
)))
...
...
crates/next-api/src/pages.rs
View file @
d372f051
...
@@ -927,7 +927,7 @@ impl PageEndpoint {
...
@@ -927,7 +927,7 @@ impl PageEndpoint {
let
ssr_module_graph
=
self
.ssr_module_graph
();
let
ssr_module_graph
=
self
.ssr_module_graph
();
let
next_dynamic_imports
=
if
let
PageEndpointType
::
Html
=
this
.ty
{
let
next_dynamic_imports
=
if
let
PageEndpointType
::
Html
=
this
.ty
{
let
client_
availability_info
=
self
.client_chunk_group
()
.await
?
.availability_info
;
let
client_
chunk_group
=
self
.client_chunk_group
()
.await
?
;
let
client_module_graph
=
self
.client_module_graph
();
let
client_module_graph
=
self
.client_module_graph
();
let
per_page_module_graph
=
*
project
.per_page_module_graph
()
.await
?
;
let
per_page_module_graph
=
*
project
.per_page_module_graph
()
.await
?
;
...
@@ -966,26 +966,21 @@ impl PageEndpoint {
...
@@ -966,26 +966,21 @@ impl PageEndpoint {
NextDynamicGraphs
::
new
(
client_module_graph
,
per_page_module_graph
)
NextDynamicGraphs
::
new
(
client_module_graph
,
per_page_module_graph
)
.get_next_dynamic_imports_for_endpoint
(
self
.client_module
())
.get_next_dynamic_imports_for_endpoint
(
self
.client_module
())
.await
?
;
.await
?
;
Some
((
next_dynamic_imports
,
client_
availability_info
))
Some
((
next_dynamic_imports
,
client_
chunk_group
))
}
else
{
}
else
{
None
None
};
};
let
dynamic_import_entries
=
if
let
Some
((
let
dynamic_import_entries
=
next_dynamic_imports
,
if
let
Some
((
next_dynamic_imports
,
client_chunk_group
))
=
next_dynamic_imports
{
client_availability_info
,
collect_next_dynamic_chunks
(
))
=
next_dynamic_imports
next_dynamic_imports
,
{
NextDynamicChunkAvailability
::
PageChunkGroup
(
&
client_chunk_group
),
collect_next_dynamic_chunks
(
)
self
.client_module_graph
(),
.await
?
project
.client_chunking_context
(),
}
else
{
next_dynamic_imports
,
DynamicImportedChunks
::
default
()
.resolved_cell
()
NextDynamicChunkAvailability
::
AvailabilityInfo
(
client_availability_info
),
};
)
.await
?
}
else
{
DynamicImportedChunks
::
default
()
.resolved_cell
()
};
let
chunking_context
:
Vc
<
Box
<
dyn
ChunkingContext
>>
=
match
runtime
{
let
chunking_context
:
Vc
<
Box
<
dyn
ChunkingContext
>>
=
match
runtime
{
NextRuntime
::
NodeJs
=>
Vc
::
upcast
(
node_chunking_context
),
NextRuntime
::
NodeJs
=>
Vc
::
upcast
(
node_chunking_context
),
...
...
crates/next-core/src/next_app/app_client_references_chunks.rs
View file @
d372f051
...
@@ -164,8 +164,8 @@ pub async fn get_app_client_references_chunks(
...
@@ -164,8 +164,8 @@ pub async fn get_app_client_references_chunks(
let
mut
current_client_chunk_group
=
ChunkGroupResult
{
let
mut
current_client_chunk_group
=
ChunkGroupResult
{
assets
:
ResolvedVc
::
cell
(
vec!
[]),
assets
:
ResolvedVc
::
cell
(
vec!
[]),
referenced_assets
:
ResolvedVc
::
cell
(
vec!
[]),
referenced_assets
:
ResolvedVc
::
cell
(
vec!
[]),
references
:
ResolvedVc
::
cell
(
vec!
[]),
availability_info
:
client_availability_info
,
availability_info
:
client_availability_info
,
async_loaders_by_module
:
FxIndexMap
::
default
(),
}
}
.resolved_cell
();
.resolved_cell
();
let
mut
current_ssr_chunk_group
=
ChunkGroupResult
::
empty_resolved
();
let
mut
current_ssr_chunk_group
=
ChunkGroupResult
::
empty_resolved
();
...
...
test/development/nested-dynamic-components/components/FeatureCard.tsx
0 → 100644
View file @
d372f051
import
dynamic
from
'next/dynamic'
const
NestedIcon
=
dynamic
(()
=>
import
(
'./nested/NestedIcon'
))
const
NestedBadge
=
dynamic
(()
=>
import
(
'./nested/NestedBadge'
))
export
default
function
FeatureCard
({
title
,
description
,
}:
{
title
:
string
description
:
string
})
{
return
(
<
div
className=
"feature-card"
>
<
div
>
<
NestedIcon
icon=
"star"
/>
<
h2
>
{
title
}
</
h2
>
<
NestedBadge
text=
"NEW"
/>
</
div
>
<
p
>
{
description
}
</
p
>
</
div
>
)
}
test/development/nested-dynamic-components/components/UserProfile.tsx
0 → 100644
View file @
d372f051
import
dynamic
from
'next/dynamic'
const
NestedIcon
=
dynamic
(()
=>
import
(
'./nested/NestedIcon'
))
const
NestedStats
=
dynamic
(()
=>
import
(
'./nested/NestedStats'
))
export
default
function
UserProfile
({
name
,
count
,
}:
{
name
:
string
count
:
number
})
{
return
(
<
div
className=
"user-profile"
>
<
NestedIcon
icon=
"user"
/>
<
h2
>
{
name
}
</
h2
>
<
NestedStats
value=
{
count
}
/>
</
div
>
)
}
test/development/nested-dynamic-components/components/nested/NestedBadge.tsx
0 → 100644
View file @
d372f051
export
default
function
NestedBadge
({
text
}:
{
text
:
string
})
{
return
<
span
className=
"nested-badge"
>
{
text
}
</
span
>
}
test/development/nested-dynamic-components/components/nested/NestedIcon.tsx
0 → 100644
View file @
d372f051
export
default
function
NestedIcon
({
icon
}:
{
icon
:
string
})
{
return
<
span
className=
"nested-icon"
>
🎯
{
icon
}
</
span
>
}
test/development/nested-dynamic-components/components/nested/NestedStats.tsx
0 → 100644
View file @
d372f051
export
default
function
NestedStats
({
value
}:
{
value
:
number
})
{
return
<
span
className=
"nested-stats"
>
Stats:
{
value
}
</
span
>
}
test/development/nested-dynamic-components/nested-dynamic-components.test.ts
0 → 100644
View file @
d372f051
import
{
nextTestSetup
}
from
'e2e-utils'
import
fs
from
'fs'
import
path
from
'path'
describe
(
'nested-dynamic-components'
,
()
=>
{
const
{
next
,
isTurbopack
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should render the page with nested dynamic components'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/'
)
expect
(
$
(
'h1'
).
text
()).
toBe
(
'Nested Dynamic Components Test'
)
expect
(
$
(
'.dynamic-component'
).
length
).
toBe
(
2
)
})
it
(
'should generate react-loadable-manifest with valid chunk references'
,
async
()
=>
{
// Trigger the page to ensure manifest is generated
await
next
.
render
(
'/'
)
// The manifest path differs between Turbopack and Webpack
// For Turbopack, each page has its own manifest in .next/dev/server/pages/<path>/
const
manifestPath
=
isTurbopack
?
'.next/dev/server/pages/index/react-loadable-manifest.json'
:
'.next/react-loadable-manifest.json'
const
manifestExists
=
await
next
.
readFile
(
manifestPath
)
.
then
(()
=>
true
)
.
catch
(()
=>
false
)
if
(
!
manifestExists
)
{
// Skip if manifest doesn't exist (e.g., no dynamic imports detected)
console
.
log
(
'Manifest not found, skipping chunk validation'
)
return
}
const
manifest
=
await
next
.
readJSON
(
manifestPath
)
// Verify the manifest is not empty - we expect entries for our dynamic imports
const
values
=
Object
.
values
(
manifest
)
expect
(
values
.
length
).
toBeGreaterThan
(
0
)
// Verify each chunk file referenced in the manifest actually exists
// This catches the bug where manifest references chunks with wrong hashes
for
(
const
entry
of
values
)
{
const
{
files
}
=
entry
as
{
id
:
string
;
files
:
string
[]
}
for
(
const
file
of
files
)
{
// The file paths in manifest are relative (e.g., "static/chunks/...")
// We need to check in .next/dev for Turbopack
const
chunkPath
=
isTurbopack
?
path
.
join
(
next
.
testDir
,
'.next/dev'
,
file
)
:
path
.
join
(
next
.
testDir
,
'.next'
,
file
)
expect
(
fs
.
existsSync
(
chunkPath
)).
toBe
(
true
)
}
}
})
})
test/development/nested-dynamic-components/pages/index.tsx
0 → 100644
View file @
d372f051
import
dynamic
from
'next/dynamic'
// Multiple dynamic components that themselves have nested dynamic imports
const
FeatureCard
=
dynamic
(()
=>
import
(
'../components/FeatureCard'
))
const
UserProfile
=
dynamic
(()
=>
import
(
'../components/UserProfile'
))
export
default
function
Page
()
{
return
(
<
div
>
<
h1
>
Nested Dynamic Components Test
</
h1
>
<
div
className=
"dynamic-component"
>
<
FeatureCard
title=
"Feature 1"
description=
"Description for feature 1"
/>
</
div
>
<
div
className=
"dynamic-component"
>
<
UserProfile
name=
"Test User"
count=
{
42
}
/>
</
div
>
</
div
>
)
}
turbopack/crates/turbopack-browser/src/chunking_context.rs
View file @
d372f051
...
@@ -14,9 +14,7 @@ use turbopack_core::{
...
@@ -14,9 +14,7 @@ use turbopack_core::{
AssetSuffix
,
Chunk
,
ChunkGroupResult
,
ChunkItem
,
ChunkType
,
ChunkableModule
,
AssetSuffix
,
Chunk
,
ChunkGroupResult
,
ChunkItem
,
ChunkType
,
ChunkableModule
,
ChunkingConfig
,
ChunkingConfigs
,
ChunkingContext
,
EntryChunkGroupResult
,
EvaluatableAsset
,
ChunkingConfig
,
ChunkingConfigs
,
ChunkingContext
,
EntryChunkGroupResult
,
EvaluatableAsset
,
EvaluatableAssets
,
MinifyType
,
SourceMapSourceType
,
SourceMapsType
,
UnusedReferences
,
EvaluatableAssets
,
MinifyType
,
SourceMapSourceType
,
SourceMapsType
,
UnusedReferences
,
UrlBehavior
,
UrlBehavior
,
availability_info
::
AvailabilityInfo
,
chunk_group
::
make_chunk_group
,
availability_info
::
AvailabilityInfo
,
chunk_group
::{
MakeChunkGroupResult
,
make_chunk_group
},
chunk_id_strategy
::
ModuleIdStrategy
,
chunk_id_strategy
::
ModuleIdStrategy
,
},
},
context
::
AssetContext
,
context
::
AssetContext
,
...
@@ -713,12 +711,7 @@ impl ChunkingContext for BrowserChunkingContext {
...
@@ -713,12 +711,7 @@ impl ChunkingContext for BrowserChunkingContext {
let
this
=
self
.await
?
;
let
this
=
self
.await
?
;
let
entries
=
chunk_group
.entries
();
let
entries
=
chunk_group
.entries
();
let
input_availability_info
=
availability_info
;
let
input_availability_info
=
availability_info
;
let
MakeChunkGroupResult
{
let
result
=
make_chunk_group
(
chunks
,
referenced_output_assets
,
references
,
availability_info
,
}
=
make_chunk_group
(
entries
,
entries
,
module_graph
,
module_graph
,
ResolvedVc
::
upcast
(
self
),
ResolvedVc
::
upcast
(
self
),
...
@@ -726,7 +719,7 @@ impl ChunkingContext for BrowserChunkingContext {
...
@@ -726,7 +719,7 @@ impl ChunkingContext for BrowserChunkingContext {
)
)
.await
?
;
.await
?
;
let
chunks
=
chunks
.await
?
;
let
chunks
=
result
.
chunks.await
?
;
let
mut
assets
=
chunks
let
mut
assets
=
chunks
.iter
()
.iter
()
...
@@ -755,9 +748,9 @@ impl ChunkingContext for BrowserChunkingContext {
...
@@ -755,9 +748,9 @@ impl ChunkingContext for BrowserChunkingContext {
Ok
(
ChunkGroupResult
{
Ok
(
ChunkGroupResult
{
assets
:
ResolvedVc
::
cell
(
assets
),
assets
:
ResolvedVc
::
cell
(
assets
),
referenced_assets
:
ResolvedVc
::
cell
(
referenced_output_assets
),
referenced_assets
:
ResolvedVc
::
cell
(
re
sult
.re
ferenced_output_assets
),
references
:
ResolvedVc
::
cell
(
references
)
,
availability_info
:
result
.availability_info
,
a
vailability_info
,
a
sync_loaders_by_module
:
result
.async_loaders_by_module
,
}
}
.cell
())
.cell
())
}
}
...
@@ -781,12 +774,7 @@ impl ChunkingContext for BrowserChunkingContext {
...
@@ -781,12 +774,7 @@ impl ChunkingContext for BrowserChunkingContext {
async
move
{
async
move
{
let
this
=
self
.await
?
;
let
this
=
self
.await
?
;
let
entries
=
chunk_group
.entries
();
let
entries
=
chunk_group
.entries
();
let
MakeChunkGroupResult
{
let
result
=
make_chunk_group
(
chunks
,
referenced_output_assets
,
references
,
availability_info
,
}
=
make_chunk_group
(
entries
,
entries
,
module_graph
,
module_graph
,
ResolvedVc
::
upcast
(
self
),
ResolvedVc
::
upcast
(
self
),
...
@@ -794,7 +782,7 @@ impl ChunkingContext for BrowserChunkingContext {
...
@@ -794,7 +782,7 @@ impl ChunkingContext for BrowserChunkingContext {
)
)
.await
?
;
.await
?
;
let
chunks
=
chunks
.await
?
;
let
chunks
=
result
.
chunks.await
?
;
let
mut
assets
:
Vec
<
ResolvedVc
<
Box
<
dyn
OutputAsset
>>>
=
chunks
let
mut
assets
:
Vec
<
ResolvedVc
<
Box
<
dyn
OutputAsset
>>>
=
chunks
.iter
()
.iter
()
...
@@ -840,9 +828,9 @@ impl ChunkingContext for BrowserChunkingContext {
...
@@ -840,9 +828,9 @@ impl ChunkingContext for BrowserChunkingContext {
Ok
(
ChunkGroupResult
{
Ok
(
ChunkGroupResult
{
assets
:
ResolvedVc
::
cell
(
assets
),
assets
:
ResolvedVc
::
cell
(
assets
),
referenced_assets
:
ResolvedVc
::
cell
(
referenced_output_assets
),
referenced_assets
:
ResolvedVc
::
cell
(
re
sult
.re
ferenced_output_assets
),
references
:
ResolvedVc
::
cell
(
references
)
,
availability_info
:
result
.availability_info
,
a
vailability_info
,
a
sync_loaders_by_module
:
result
.async_loaders_by_module
,
}
}
.cell
())
.cell
())
}
}
...
...
turbopack/crates/turbopack-core/src/chunk/chunk_group.rs
View file @
d372f051
...
@@ -3,7 +3,7 @@ use std::{collections::HashSet, sync::atomic::AtomicBool};
...
@@ -3,7 +3,7 @@ use std::{collections::HashSet, sync::atomic::AtomicBool};
use
anyhow
::{
Context
,
Result
};
use
anyhow
::{
Context
,
Result
};
use
rustc_hash
::
FxHashMap
;
use
rustc_hash
::
FxHashMap
;
use
turbo_rcstr
::
rcstr
;
use
turbo_rcstr
::
rcstr
;
use
turbo_tasks
::{
FxIndexSet
,
ResolvedVc
,
TryFlatJoinIterExt
,
TryJoinIterExt
,
Vc
};
use
turbo_tasks
::{
FxIndex
Map
,
FxIndex
Set
,
ResolvedVc
,
TryFlatJoinIterExt
,
TryJoinIterExt
,
Vc
};
use
super
::{
use
super
::{
ChunkGroupContent
,
ChunkItemWithAsyncModuleInfo
,
ChunkingContext
,
ChunkGroupContent
,
ChunkItemWithAsyncModuleInfo
,
ChunkingContext
,
...
@@ -11,7 +11,7 @@ use super::{
...
@@ -11,7 +11,7 @@ use super::{
};
};
use
crate
::{
use
crate
::{
chunk
::{
chunk
::{
ChunkableModule
,
ChunkingType
,
Chunks
,
Chunk
Item
,
Chunk
ableModule
,
ChunkingType
,
Chunks
,
available_modules
::
AvailableModuleItem
,
available_modules
::
AvailableModuleItem
,
chunk_item_batch
::{
ChunkItemBatchGroup
,
ChunkItemOrBatchWithAsyncModuleInfo
},
chunk_item_batch
::{
ChunkItemBatchGroup
,
ChunkItemOrBatchWithAsyncModuleInfo
},
},
},
...
@@ -37,8 +37,24 @@ use crate::{
...
@@ -37,8 +37,24 @@ use crate::{
pub
struct
MakeChunkGroupResult
{
pub
struct
MakeChunkGroupResult
{
pub
chunks
:
ResolvedVc
<
Chunks
>
,
pub
chunks
:
ResolvedVc
<
Chunks
>
,
pub
referenced_output_assets
:
Vec
<
ResolvedVc
<
Box
<
dyn
OutputAsset
>>>
,
pub
referenced_output_assets
:
Vec
<
ResolvedVc
<
Box
<
dyn
OutputAsset
>>>
,
pub
references
:
Vec
<
ResolvedVc
<
Box
<
dyn
OutputAssetsReference
>>>
,
pub
availability_info
:
AvailabilityInfo
,
pub
availability_info
:
AvailabilityInfo
,
/// Map from async module to its async loader chunk item.
/// This preserves the module→loader relationship for async loaders,
/// allowing downstream code to look up pre-computed chunk outputs
/// instead of recomputing them.
#[allow(clippy
::
type_complexity)]
pub
async_loaders_by_module
:
FxIndexMap
<
ResolvedVc
<
Box
<
dyn
ChunkableModule
>>
,
ResolvedVc
<
Box
<
dyn
ChunkItem
>>>
,
}
impl
MakeChunkGroupResult
{
// Returns all the assets referenced by this chunk group.
pub
fn
references
(
&
self
)
->
Vec
<
ResolvedVc
<
Box
<
dyn
OutputAssetsReference
>>>
{
self
.async_loaders_by_module
.values
()
.map
(|
loader
|
ResolvedVc
::
upcast
(
*
loader
))
.collect
()
}
}
}
/// Creates a chunk group from a set of entries.
/// Creates a chunk group from a set of entries.
...
@@ -121,19 +137,28 @@ pub async fn make_chunk_group(
...
@@ -121,19 +137,28 @@ pub async fn make_chunk_group(
}
else
{
}
else
{
availability_info
availability_info
};
};
let
async_loaders
=
async_modules
// Build async loaders while preserving the module→loader mapping
let
async_loaders_with_modules
:
Vec
<
_
>
=
async_modules
.into_iter
()
.into_iter
()
.map
(
async
|
module
|
{
.map
(
async
|
module
|
{
chunking_context
let
loader
=
chunking_context
.async_loader_chunk_item
(
*
module
,
module_graph
,
async_availability_info
)
.async_loader_chunk_item
(
*
module
,
module_graph
,
async_availability_info
)
.to_resolved
()
.to_resolved
()
.await
.await
?
;
Ok
((
module
,
loader
))
})
})
.try_join
()
.try_join
()
.await
?
;
.await
?
;
let
async_loader_chunk_items
=
async_loaders
.iter
()
.map
(|
&
chunk_item
|
{
// Build the module→loader mapping
let
async_loaders_by_module
:
FxIndexMap
<
_
,
_
>
=
async_loaders_with_modules
.iter
()
.map
(|(
module
,
loader
)|
(
*
module
,
*
loader
))
.collect
();
let
async_loader_chunk_items
=
async_loaders_with_modules
.iter
()
.map
(|(
_
,
chunk_item
)|
{
ChunkItemOrBatchWithAsyncModuleInfo
::
ChunkItem
(
ChunkItemWithAsyncModuleInfo
{
ChunkItemOrBatchWithAsyncModuleInfo
::
ChunkItem
(
ChunkItemWithAsyncModuleInfo
{
chunk_item
,
chunk_item
:
*
chunk_item
,
module
:
None
,
module
:
None
,
async_info
:
None
,
async_info
:
None
,
})
})
...
@@ -165,8 +190,8 @@ pub async fn make_chunk_group(
...
@@ -165,8 +190,8 @@ pub async fn make_chunk_group(
Ok
(
MakeChunkGroupResult
{
Ok
(
MakeChunkGroupResult
{
chunks
,
chunks
,
referenced_output_assets
,
referenced_output_assets
,
references
:
ResolvedVc
::
upcast_vec
(
async_loaders
),
availability_info
:
new_availability_info
,
availability_info
:
new_availability_info
,
async_loaders_by_module
,
})
})
}
}
...
...
turbopack/crates/turbopack-core/src/chunk/chunking_context.rs
View file @
d372f051
...
@@ -3,7 +3,9 @@ use bincode::{Decode, Encode};
...
@@ -3,7 +3,9 @@ use bincode::{Decode, Encode};
use
rustc_hash
::{
FxHashMap
,
FxHashSet
};
use
rustc_hash
::{
FxHashMap
,
FxHashSet
};
use
serde
::{
Deserialize
,
Serialize
};
use
serde
::{
Deserialize
,
Serialize
};
use
turbo_rcstr
::
RcStr
;
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks
::{
NonLocalValue
,
ResolvedVc
,
TaskInput
,
Upcast
,
Vc
,
trace
::
TraceRawVcs
};
use
turbo_tasks
::{
FxIndexMap
,
NonLocalValue
,
ResolvedVc
,
TaskInput
,
Upcast
,
Vc
,
trace
::
TraceRawVcs
,
};
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbo_tasks_hash
::
DeterministicHash
;
use
turbo_tasks_hash
::
DeterministicHash
;
...
@@ -22,8 +24,8 @@ use crate::{
...
@@ -22,8 +24,8 @@ use crate::{
module_batches
::
BatchingConfig
,
module_batches
::
BatchingConfig
,
},
},
output
::{
output
::{
ExpandOutputAssetsInput
,
OutputAsset
,
OutputAssets
,
OutputAssets
References
,
ExpandOutputAssetsInput
,
OutputAsset
,
OutputAssets
,
OutputAssets
WithReferenced
,
OutputAssetsWithReferenced
,
expand_output_assets
,
expand_output_assets
,
},
},
reference
::
ModuleReference
,
reference
::
ModuleReference
,
};
};
...
@@ -127,8 +129,15 @@ pub enum ChunkGroupType {
...
@@ -127,8 +129,15 @@ pub enum ChunkGroupType {
pub
struct
ChunkGroupResult
{
pub
struct
ChunkGroupResult
{
pub
assets
:
ResolvedVc
<
OutputAssets
>
,
pub
assets
:
ResolvedVc
<
OutputAssets
>
,
pub
referenced_assets
:
ResolvedVc
<
OutputAssets
>
,
pub
referenced_assets
:
ResolvedVc
<
OutputAssets
>
,
pub
references
:
ResolvedVc
<
OutputAssetsReferences
>
,
pub
availability_info
:
AvailabilityInfo
,
pub
availability_info
:
AvailabilityInfo
,
/// Map from async module to its async loader chunk item.
/// This preserves the module→loader relationship for async loaders,
/// allowing downstream code to look up pre-computed chunk outputs
/// instead of recomputing them.
#[bincode(with
=
"turbo_bincode::indexmap"
)]
#[allow(clippy
::
type_complexity)]
pub
async_loaders_by_module
:
FxIndexMap
<
ResolvedVc
<
Box
<
dyn
ChunkableModule
>>
,
ResolvedVc
<
Box
<
dyn
ChunkItem
>>>
,
}
}
impl
ChunkGroupResult
{
impl
ChunkGroupResult
{
...
@@ -136,8 +145,8 @@ impl ChunkGroupResult {
...
@@ -136,8 +145,8 @@ impl ChunkGroupResult {
ChunkGroupResult
{
ChunkGroupResult
{
assets
:
ResolvedVc
::
cell
(
vec!
[]),
assets
:
ResolvedVc
::
cell
(
vec!
[]),
referenced_assets
:
ResolvedVc
::
cell
(
vec!
[]),
referenced_assets
:
ResolvedVc
::
cell
(
vec!
[]),
references
:
ResolvedVc
::
cell
(
vec!
[]),
availability_info
:
AvailabilityInfo
::
root
(),
availability_info
:
AvailabilityInfo
::
root
(),
async_loaders_by_module
:
FxIndexMap
::
default
(),
}
}
.cell
()
.cell
()
}
}
...
@@ -146,8 +155,8 @@ impl ChunkGroupResult {
...
@@ -146,8 +155,8 @@ impl ChunkGroupResult {
ChunkGroupResult
{
ChunkGroupResult
{
assets
:
ResolvedVc
::
cell
(
vec!
[]),
assets
:
ResolvedVc
::
cell
(
vec!
[]),
referenced_assets
:
ResolvedVc
::
cell
(
vec!
[]),
referenced_assets
:
ResolvedVc
::
cell
(
vec!
[]),
references
:
ResolvedVc
::
cell
(
vec!
[]),
availability_info
:
AvailabilityInfo
::
root
(),
availability_info
:
AvailabilityInfo
::
root
(),
async_loaders_by_module
:
FxIndexMap
::
default
(),
}
}
.resolved_cell
()
.resolved_cell
()
}
}
...
@@ -157,10 +166,16 @@ impl ChunkGroupResult {
...
@@ -157,10 +166,16 @@ impl ChunkGroupResult {
impl
ChunkGroupResult
{
impl
ChunkGroupResult
{
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
output_assets_with_referenced
(
&
self
)
->
Result
<
Vc
<
OutputAssetsWithReferenced
>>
{
pub
async
fn
output_assets_with_referenced
(
&
self
)
->
Result
<
Vc
<
OutputAssetsWithReferenced
>>
{
let
references
:
Vec
<
_
>
=
self
.async_loaders_by_module
.values
()
.map
(|
loader
|
ResolvedVc
::
upcast
(
*
loader
))
.collect
();
Ok
(
OutputAssetsWithReferenced
{
Ok
(
OutputAssetsWithReferenced
{
assets
:
self
.assets
,
assets
:
self
.assets
,
referenced_assets
:
self
.referenced_assets
,
referenced_assets
:
self
.referenced_assets
,
references
:
self
.references
,
references
:
ResolvedVc
::
cell
(
references
)
,
}
}
.cell
())
.cell
())
}
}
...
@@ -168,6 +183,11 @@ impl ChunkGroupResult {
...
@@ -168,6 +183,11 @@ impl ChunkGroupResult {
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
concatenate
(
&
self
,
next
:
Vc
<
Self
>
)
->
Result
<
Vc
<
Self
>>
{
pub
async
fn
concatenate
(
&
self
,
next
:
Vc
<
Self
>
)
->
Result
<
Vc
<
Self
>>
{
let
next
=
next
.await
?
;
let
next
=
next
.await
?
;
// Merge async_loaders_by_module maps
let
mut
merged_async_loaders
=
self
.async_loaders_by_module
.clone
();
merged_async_loaders
.extend
(
next
.async_loaders_by_module
.iter
()
.map
(|(
k
,
v
)|
(
*
k
,
*
v
)));
Ok
(
ChunkGroupResult
{
Ok
(
ChunkGroupResult
{
assets
:
self
.assets
.concatenate
(
*
next
.assets
)
.to_resolved
()
.await
?
,
assets
:
self
.assets
.concatenate
(
*
next
.assets
)
.to_resolved
()
.await
?
,
referenced_assets
:
self
referenced_assets
:
self
...
@@ -175,12 +195,8 @@ impl ChunkGroupResult {
...
@@ -175,12 +195,8 @@ impl ChunkGroupResult {
.concatenate
(
*
next
.referenced_assets
)
.concatenate
(
*
next
.referenced_assets
)
.to_resolved
()
.to_resolved
()
.await
?
,
.await
?
,
references
:
self
.references
.concatenate
(
*
next
.references
)
.to_resolved
()
.await
?
,
availability_info
:
next
.availability_info
,
availability_info
:
next
.availability_info
,
async_loaders_by_module
:
merged_async_loaders
,
}
}
.cell
())
.cell
())
}
}
...
@@ -196,11 +212,9 @@ impl ChunkGroupResult {
...
@@ -196,11 +212,9 @@ impl ChunkGroupResult {
.copied
()
.copied
()
.map
(
ExpandOutputAssetsInput
::
Asset
)
.map
(
ExpandOutputAssetsInput
::
Asset
)
.chain
(
.chain
(
self
.references
self
.async_loaders_by_module
.await
?
.values
()
.into_iter
()
.map
(|
v
|
ExpandOutputAssetsInput
::
Reference
(
ResolvedVc
::
upcast
(
*
v
))),
.copied
()
.map
(
ExpandOutputAssetsInput
::
Reference
),
),
),
false
,
false
,
)
)
...
@@ -217,6 +231,13 @@ impl ChunkGroupResult {
...
@@ -217,6 +231,13 @@ impl ChunkGroupResult {
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
referenced_assets
(
&
self
)
->
Result
<
Vc
<
OutputAssets
>>
{
pub
async
fn
referenced_assets
(
&
self
)
->
Result
<
Vc
<
OutputAssets
>>
{
// Derive references from async_loaders_by_module
let
references
=
self
.async_loaders_by_module
.values
()
.copied
()
.map
(
ResolvedVc
::
upcast
);
Ok
(
Vc
::
cell
(
Ok
(
Vc
::
cell
(
expand_output_assets
(
expand_output_assets
(
self
.referenced_assets
self
.referenced_assets
...
@@ -224,13 +245,7 @@ impl ChunkGroupResult {
...
@@ -224,13 +245,7 @@ impl ChunkGroupResult {
.into_iter
()
.into_iter
()
.copied
()
.copied
()
.map
(
ExpandOutputAssetsInput
::
Asset
)
.map
(
ExpandOutputAssetsInput
::
Asset
)
.chain
(
.chain
(
references
.map
(
ExpandOutputAssetsInput
::
Reference
)),
self
.references
.await
?
.into_iter
()
.copied
()
.map
(
ExpandOutputAssetsInput
::
Reference
),
),
false
,
false
,
)
)
.await
?
,
.await
?
,
...
...
turbopack/crates/turbopack-nodejs/src/chunking_context.rs
View file @
d372f051
...
@@ -9,8 +9,7 @@ use turbopack_core::{
...
@@ -9,8 +9,7 @@ use turbopack_core::{
AssetSuffix
,
Chunk
,
ChunkGroupResult
,
ChunkItem
,
ChunkType
,
ChunkableModule
,
AssetSuffix
,
Chunk
,
ChunkGroupResult
,
ChunkItem
,
ChunkType
,
ChunkableModule
,
ChunkingConfig
,
ChunkingConfigs
,
ChunkingContext
,
EntryChunkGroupResult
,
EvaluatableAssets
,
ChunkingConfig
,
ChunkingConfigs
,
ChunkingContext
,
EntryChunkGroupResult
,
EvaluatableAssets
,
MinifyType
,
SourceMapSourceType
,
SourceMapsType
,
UnusedReferences
,
UrlBehavior
,
MinifyType
,
SourceMapSourceType
,
SourceMapsType
,
UnusedReferences
,
UrlBehavior
,
availability_info
::
AvailabilityInfo
,
availability_info
::
AvailabilityInfo
,
chunk_group
::
make_chunk_group
,
chunk_group
::{
MakeChunkGroupResult
,
make_chunk_group
},
chunk_id_strategy
::
ModuleIdStrategy
,
chunk_id_strategy
::
ModuleIdStrategy
,
},
},
environment
::
Environment
,
environment
::
Environment
,
...
@@ -493,12 +492,7 @@ impl ChunkingContext for NodeJsChunkingContext {
...
@@ -493,12 +492,7 @@ impl ChunkingContext for NodeJsChunkingContext {
let
span
=
tracing
::
info_span!
(
"chunking"
,
name
=
display
(
ident
.to_string
()
.await
?
));
let
span
=
tracing
::
info_span!
(
"chunking"
,
name
=
display
(
ident
.to_string
()
.await
?
));
async
move
{
async
move
{
let
modules
=
chunk_group
.entries
();
let
modules
=
chunk_group
.entries
();
let
MakeChunkGroupResult
{
let
result
=
make_chunk_group
(
chunks
,
referenced_output_assets
,
references
,
availability_info
,
}
=
make_chunk_group
(
modules
,
modules
,
module_graph
,
module_graph
,
ResolvedVc
::
upcast
(
self
),
ResolvedVc
::
upcast
(
self
),
...
@@ -506,7 +500,7 @@ impl ChunkingContext for NodeJsChunkingContext {
...
@@ -506,7 +500,7 @@ impl ChunkingContext for NodeJsChunkingContext {
)
)
.await
?
;
.await
?
;
let
chunks
=
chunks
.await
?
;
let
chunks
=
result
.
chunks.await
?
;
let
assets
=
chunks
let
assets
=
chunks
.iter
()
.iter
()
...
@@ -516,9 +510,9 @@ impl ChunkingContext for NodeJsChunkingContext {
...
@@ -516,9 +510,9 @@ impl ChunkingContext for NodeJsChunkingContext {
Ok
(
ChunkGroupResult
{
Ok
(
ChunkGroupResult
{
assets
:
ResolvedVc
::
cell
(
assets
),
assets
:
ResolvedVc
::
cell
(
assets
),
referenced_assets
:
ResolvedVc
::
cell
(
referenced_output_assets
),
referenced_assets
:
ResolvedVc
::
cell
(
re
sult
.re
ferenced_output_assets
),
references
:
ResolvedVc
::
cell
(
references
)
,
availability_info
:
result
.availability_info
,
a
vailability_info
,
a
sync_loaders_by_module
:
result
.async_loaders_by_module
,
}
}
.cell
())
.cell
())
}
}
...
@@ -547,12 +541,7 @@ impl ChunkingContext for NodeJsChunkingContext {
...
@@ -547,12 +541,7 @@ impl ChunkingContext for NodeJsChunkingContext {
.iter
()
.iter
()
.map
(|
&
asset
|
ResolvedVc
::
upcast
::
<
Box
<
dyn
Module
>>
(
asset
));
.map
(|
&
asset
|
ResolvedVc
::
upcast
::
<
Box
<
dyn
Module
>>
(
asset
));
let
MakeChunkGroupResult
{
let
result
=
make_chunk_group
(
chunks
,
mut
referenced_output_assets
,
references
,
availability_info
,
}
=
make_chunk_group
(
entries
,
entries
,
module_graph
,
module_graph
,
ResolvedVc
::
upcast
(
self
),
ResolvedVc
::
upcast
(
self
),
...
@@ -560,7 +549,9 @@ impl ChunkingContext for NodeJsChunkingContext {
...
@@ -560,7 +549,9 @@ impl ChunkingContext for NodeJsChunkingContext {
)
)
.await
?
;
.await
?
;
let
chunks
=
chunks
.await
?
;
let
chunks
=
result
.chunks.await
?
;
let
references
=
result
.references
();
let
mut
referenced_output_assets
=
result
.referenced_output_assets
;
let
extra_chunks
=
extra_chunks
.await
?
;
let
extra_chunks
=
extra_chunks
.await
?
;
let
mut
other_chunks
=
chunks
let
mut
other_chunks
=
chunks
...
@@ -594,7 +585,7 @@ impl ChunkingContext for NodeJsChunkingContext {
...
@@ -594,7 +585,7 @@ impl ChunkingContext for NodeJsChunkingContext {
Ok
(
EntryChunkGroupResult
{
Ok
(
EntryChunkGroupResult
{
asset
,
asset
,
availability_info
,
availability_info
:
result
.availability_info
,
}
}
.cell
())
.cell
())
}
}
...
...
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