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
95e991e0
Commit
95e991e0
authored
Feb 21, 2025
by
Niklas Mischkulnig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use correct ChunkGroups for chunking
parent
6d82715d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
607 additions
and
204 deletions
+607
-204
app.rs
crates/next-api/src/app.rs
+24
-6
instrumentation.rs
crates/next-api/src/instrumentation.rs
+2
-2
middleware.rs
crates/next-api/src/middleware.rs
+2
-2
pages.rs
crates/next-api/src/pages.rs
+2
-2
app_client_references_chunks.rs
...es/next-core/src/next_app/app_client_references_chunks.rs
+256
-124
app_entry.rs
crates/next-core/src/next_app/app_entry.rs
+2
-0
app_page_entry.rs
crates/next-core/src/next_app/app_page_entry.rs
+20
-11
app_route_entry.rs
crates/next-core/src/next_app/app_route_entry.rs
+22
-13
client_reference_manifest.rs
...next-core/src/next_manifests/client_reference_manifest.rs
+19
-4
primitives.rs
turbopack/crates/turbo-tasks/src/primitives.rs
+78
-3
mod.rs
turbopack/crates/turbopack-cli/src/build/mod.rs
+5
-1
chunk_group_info.rs
...rates/turbopack-core/src/module_graph/chunk_group_info.rs
+170
-33
html.rs
turbopack/crates/turbopack-dev-server/src/html.rs
+3
-1
webpack.rs
turbopack/crates/turbopack-node/src/transforms/webpack.rs
+1
-1
snapshot.rs
turbopack/crates/turbopack-tests/tests/snapshot.rs
+1
-1
No files found.
crates/next-api/src/app.rs
View file @
95e991e0
...
...
@@ -1328,16 +1328,31 @@ impl AppEndpoint {
*
client_chunking_context
,
availability_info
,
ssr_chunking_context
.map
(|
ctx
|
*
ctx
),
if
let
Some
(
rsc_edge_inner
)
=
app_entry
.rsc_edge_inner
{
ChunkGroup
::
Async
(
rsc_edge_inner
)
}
else
{
ChunkGroup
::
Entry
([
app_entry
.rsc_entry
]
.into_iter
()
.collect
())
},
project
.project_path
(),
)
.to_resolved
()
.await
?
;
let
client_references_chunks_ref
=
client_references_chunks
.await
?
;
for
&
assets
in
client_references_chunks_ref
for
assets
in
client_references_chunks_ref
.layout_segment_client_chunks
.values
()
{
client_assets
.extend
(
assets
.all_assets
()
.await
?
.iter
()
.copied
());
client_assets
.extend
(
assets
.iter
()
.map
(|
a
|
a
.all_assets
())
.try_join
()
.await
?
.iter
()
.flatten
()
.copied
(),
);
}
for
&
assets
in
client_references_chunks_ref
.client_component_client_chunks
...
...
@@ -1790,7 +1805,7 @@ impl AppEndpoint {
let
chunk_group2_assets
=
chunking_context
.evaluated_chunk_group_assets
(
app_entry
.rsc_entry
.ident
(),
ChunkGroup
::
Entry
(
vec!
[
app_entry
.rsc_entry
]
),
ChunkGroup
::
Entry
(
[
app_entry
.rsc_entry
]
.into_iter
()
.collect
()
),
module_graph
,
chunk_group1
.await
?
.availability_info
,
);
...
...
@@ -1803,7 +1818,8 @@ impl AppEndpoint {
async
{
let
mut
current_chunk_group
=
ChunkGroupResult
::
empty_resolved
();
let
entry_chunk_group
=
ChunkGroup
::
Entry
(
vec!
[
app_entry
.rsc_entry
]);
let
entry_chunk_group
=
ChunkGroup
::
Entry
([
app_entry
.rsc_entry
]
.into_iter
()
.collect
());
let
chunk_group_info
=
module_graph
.chunk_group_info
();
...
...
@@ -1822,7 +1838,9 @@ impl AppEndpoint {
.iter
()
.map
(
async
|
m
|
Ok
(
ResolvedVc
::
upcast
(
m
.await
?
.module
)))
.try_join
()
.await
?
;
.await
?
.into_iter
()
.collect
();
let
chunk_group
=
chunking_context
.chunk_group
(
AssetIdent
::
from_path
(
...
...
@@ -1832,7 +1850,7 @@ impl AppEndpoint {
ChunkGroup
::
SharedMerged
{
merge_tag
:
NEXT_SERVER_UTILITY_MERGE_TAG
.clone
(),
entries
:
server_utils
,
parent
:
parent_chunk_group
,
parent
:
parent_chunk_group
as
usize
,
},
module_graph
,
AvailabilityInfo
::
root
(),
...
...
crates/next-api/src/instrumentation.rs
View file @
95e991e0
...
...
@@ -105,7 +105,7 @@ impl InstrumentationEndpoint {
let
edge_chunking_context
=
this
.project
.edge_chunking_context
(
false
);
Ok
(
edge_chunking_context
.evaluated_chunk_group_assets
(
module
.ident
(),
ChunkGroup
::
Entry
(
vec!
[
module
]
),
ChunkGroup
::
Entry
(
[
module
]
.into_iter
()
.collect
()
),
module_graph
,
AvailabilityInfo
::
root
(),
))
...
...
@@ -126,7 +126,7 @@ impl InstrumentationEndpoint {
.node_root
()
.await
?
.join
(
"server/instrumentation.js"
)
?
,
ChunkGroup
::
Entry
(
vec!
[
userland_module
]
),
ChunkGroup
::
Entry
(
[
userland_module
]
.into_iter
()
.collect
()
),
module_graph
,
OutputAssets
::
empty
(),
OutputAssets
::
empty
(),
...
...
crates/next-api/src/middleware.rs
View file @
95e991e0
...
...
@@ -115,7 +115,7 @@ impl MiddlewareEndpoint {
let
edge_chunking_context
=
this
.project
.edge_chunking_context
(
false
);
let
edge_chunk_grou
=
edge_chunking_context
.evaluated_chunk_group_assets
(
module
.ident
(),
ChunkGroup
::
Entry
(
vec!
[
module
]
),
ChunkGroup
::
Entry
(
[
module
]
.into_iter
()
.collect
()
),
module_graph
,
AvailabilityInfo
::
root
(),
);
...
...
@@ -137,7 +137,7 @@ impl MiddlewareEndpoint {
.node_root
()
.await
?
.join
(
"server/middleware.js"
)
?
,
ChunkGroup
::
Entry
(
vec!
[
userland_module
]
),
ChunkGroup
::
Entry
(
[
userland_module
]
.into_iter
()
.collect
()
),
module_graph
,
OutputAssets
::
empty
(),
OutputAssets
::
empty
(),
...
...
crates/next-api/src/pages.rs
View file @
95e991e0
...
...
@@ -1022,7 +1022,7 @@ impl PageEndpoint {
if
is_edge
{
let
chunk_assets
=
edge_chunking_context
.evaluated_chunk_group_assets
(
ssr_module
.ident
(),
ChunkGroup
::
Entry
(
vec!
[
ssr_module
]
),
ChunkGroup
::
Entry
(
[
ssr_module
]
.into_iter
()
.collect
()
),
ssr_module_graph
,
current_chunk_group
.await
?
.availability_info
,
);
...
...
@@ -1050,7 +1050,7 @@ impl PageEndpoint {
let
ssr_entry_chunk
=
node_chunking_context
.entry_chunk_group_asset
(
ssr_entry_chunk_path
,
ChunkGroup
::
Entry
(
vec!
[
ssr_module
]
),
ChunkGroup
::
Entry
(
[
ssr_module
]
.into_iter
()
.collect
()
),
ssr_module_graph
,
current_chunk_group
.primary_assets
(),
current_chunk_group
.referenced_assets
(),
...
...
crates/next-core/src/next_app/app_client_references_chunks.rs
View file @
95e991e0
This diff is collapsed.
Click to expand it.
crates/next-core/src/next_app/app_entry.rs
View file @
95e991e0
...
...
@@ -14,6 +14,8 @@ pub struct AppEntry {
pub
original_name
:
RcStr
,
/// The RSC module asset for the route or page.
pub
rsc_entry
:
ResolvedVc
<
Box
<
dyn
Module
>>
,
/// For edge, the module wrapped by the sync-ifying facade
pub
rsc_edge_inner
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
/// The source code config for this entry.
pub
config
:
ResolvedVc
<
NextSegmentConfig
>
,
}
crates/next-core/src/next_app/app_page_entry.rs
View file @
95e991e0
...
...
@@ -101,27 +101,41 @@ pub async fn get_app_page_entry(
AssetContent
::
file
(
FileContent
::
Content
(
file
)
.cell
()),
);
let
mut
rsc_entry
=
module_asset_context
let
rsc_entry
=
module_asset_context
.process
(
Vc
::
upcast
(
source
),
ReferenceType
::
Internal
(
ResolvedVc
::
cell
(
inner_assets
)),
)
.module
();
if
is_edge
{
rsc_entry
=
wrap_edge_page
(
let
(
rsc_entry
,
rsc_edge_inner
)
=
if
is_edge
{
let
rsc_entry
=
wrap_edge_page
(
*
ResolvedVc
::
upcast
(
module_asset_context
),
project_root
.clone
(),
rsc_entry
,
page
,
page
.clone
()
,
next_config
,
);
)
.to_resolved
()
.await
?
;
(
wrap_edge_entry
(
*
ResolvedVc
::
upcast
(
module_asset_context
),
project_root
,
*
rsc_entry
,
app_function_name
(
&
page
)
.into
(),
),
Some
(
rsc_entry
),
)
}
else
{
(
rsc_entry
,
None
)
};
Ok
(
AppEntry
{
pathname
,
original_name
,
rsc_entry
:
rsc_entry
.to_resolved
()
.await
?
,
rsc_edge_inner
,
config
:
config
.to_resolved
()
.await
?
,
}
.cell
())
...
...
@@ -213,10 +227,5 @@ async fn wrap_edge_page(
)
.module
();
Ok
(
wrap_edge_entry
(
asset_context
,
project_root
,
wrapped
,
app_function_name
(
&
page
)
.into
(),
))
Ok
(
wrapped
)
}
crates/next-core/src/next_app/app_route_entry.rs
View file @
95e991e0
...
...
@@ -101,27 +101,41 @@ pub async fn get_app_route_entry(
inner
=>
userland_module
};
let
mut
rsc_entry
=
module_asset_context
let
rsc_entry
=
module_asset_context
.process
(
virtual_source
,
ReferenceType
::
Internal
(
ResolvedVc
::
cell
(
inner_assets
)),
)
.module
();
if
is_edge
{
rsc_entry
=
wrap_edge_route
(
let
(
rsc_entry
,
rsc_edge_inner
)
=
if
is_edge
{
let
rsc_entry
=
wrap_edge_route
(
Vc
::
upcast
(
module_asset_context
),
project_root
,
project_root
.clone
()
,
rsc_entry
,
page
,
page
.clone
()
,
next_config
,
);
}
)
.to_resolved
()
.await
?
;
(
wrap_edge_entry
(
Vc
::
upcast
(
module_asset_context
),
project_root
,
*
rsc_entry
,
app_function_name
(
&
page
)
.into
(),
),
Some
(
rsc_entry
),
)
}
else
{
(
rsc_entry
,
None
)
};
Ok
(
AppEntry
{
pathname
,
original_name
,
rsc_entry
:
rsc_entry
.to_resolved
()
.await
?
,
rsc_edge_inner
,
config
:
config
.to_resolved
()
.await
?
,
}
.cell
())
...
...
@@ -213,10 +227,5 @@ async fn wrap_edge_route(
)
.module
();
Ok
(
wrap_edge_entry
(
asset_context
,
project_root
.clone
(),
wrapped
,
app_function_name
(
&
page
)
.into
(),
))
Ok
(
wrapped
)
}
crates/next-core/src/next_manifests/client_reference_manifest.rs
View file @
95e991e0
...
...
@@ -409,8 +409,16 @@ async fn build_manifest(
}
}
// The server utility chunks are merged into the first layout segment
let
mut
server_utility_chunks
=
layout_segment_client_chunks
.get
(
&
None
);
// per layout segment chunks need to be emitted into the manifest too
for
(
server_component
,
client_assets
)
in
layout_segment_client_chunks
.iter
()
{
let
Some
(
server_component
)
=
server_component
else
{
// Handled via server_utility_chunks
continue
;
};
// Use source_path() to get the original source path (e.g., page.mdx) instead of
// server_path() which returns the transformed path (e.g., page.mdx.tsx).
// This ensures the manifest key matches what the LoaderTree stores and what
...
...
@@ -430,10 +438,17 @@ async fn build_manifest(
.entry
(
server_component_name
)
.or_default
();
let
client_chunks
=
client_assets
.primary_assets
()
.await
?
;
let
client_chunks_with_path
=
cached_chunk_paths
(
&
mut
client_chunk_path_cache
,
client_chunks
.iter
()
.copied
())
.await
?
;
let
client_chunks
=
client_assets
.iter
()
.chain
(
server_utility_chunks
.take
()
.into_iter
()
.flatten
())
.map
(|
assets
|
assets
.primary_assets
())
.try_join
()
.await
?
;
let
client_chunks_with_path
=
cached_chunk_paths
(
&
mut
client_chunk_path_cache
,
client_chunks
.iter
()
.flatten
()
.copied
(),
)
.await
?
;
// Inlining breaks HMR so it is always disabled in dev.
let
inlined_css
=
*
next_config
.inline_css
()
.await
?
&&
mode
.is_production
();
...
...
turbopack/crates/turbo-tasks/src/primitives.rs
View file @
95e991e0
use
std
::
time
::
Duration
;
use
std
::{
hash
::{
BuildHasher
,
Hash
},
ops
::{
Deref
,
DerefMut
},
time
::
Duration
,
};
use
anyhow
::
Result
;
use
bincode
::{
Decode
,
Encode
,
de
::
Decoder
,
enc
::
Encoder
,
error
::{
DecodeError
,
EncodeError
},
};
use
rustc_hash
::
FxBuildHasher
;
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks_macros
::
primitive
as
__turbo_tasks_internal_primitive
;
use
turbo_tasks_macros
::
{
TraceRawVcs
,
primitive
as
__turbo_tasks_internal_primitive
}
;
use
crate
::{
self
as
turbo_tasks
,
Vc
,
self
as
turbo_tasks
,
FxIndexSet
,
NonLocalValue
,
TaskInput
,
Vc
,
value_type
::{
ManualDecodeWrapper
,
ManualEncodeWrapper
},
};
...
...
@@ -75,3 +81,72 @@ impl<Context> Decode<Context> for JsonValueDecodeWrapper {
Ok
(
Self
(
turbo_bincode
::
serde_self_describing
::
decode
(
decoder
)
?
))
}
}
/// An IndexSet with a Hash implementation that is order-independent (and just like IndexSet,
/// equality is also order-independent).
#[derive(Clone,
Debug,
PartialEq,
Eq,
Decode,
Encode,
TraceRawVcs)]
pub
struct
HashableIndexSet
<
T
:
Hash
+
Eq
+
Decode
<
()
>
+
Encode
>
(
#[bincode(with
=
"turbo_bincode::indexset"
)]
pub
FxIndexSet
<
T
>
,
);
impl
<
T
:
Hash
+
Eq
+
Decode
<
()
>
+
Encode
>
From
<
FxIndexSet
<
T
>>
for
HashableIndexSet
<
T
>
{
fn
from
(
set
:
FxIndexSet
<
T
>
)
->
Self
{
HashableIndexSet
(
set
)
}
}
impl
<
T
:
Hash
+
Eq
+
Decode
<
()
>
+
Encode
>
FromIterator
<
T
>
for
HashableIndexSet
<
T
>
{
fn
from_iter
<
I
:
IntoIterator
<
Item
=
T
>>
(
iter
:
I
)
->
Self
{
HashableIndexSet
(
iter
.into_iter
()
.collect
())
}
}
impl
<
T
:
Hash
+
Eq
+
Decode
<
()
>
+
Encode
>
Deref
for
HashableIndexSet
<
T
>
{
type
Target
=
FxIndexSet
<
T
>
;
fn
deref
(
&
self
)
->
&
Self
::
Target
{
&
self
.
0
}
}
impl
<
T
:
Hash
+
Eq
+
Decode
<
()
>
+
Encode
>
DerefMut
for
HashableIndexSet
<
T
>
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
Self
::
Target
{
&
mut
self
.
0
}
}
impl
<
T
:
Hash
+
Eq
+
Decode
<
()
>
+
Encode
>
Hash
for
HashableIndexSet
<
T
>
{
fn
hash
<
H
:
std
::
hash
::
Hasher
>
(
&
self
,
state
:
&
mut
H
)
{
let
mut
result
=
0u64
;
for
item
in
self
.iter
()
{
let
item_hash
=
FxBuildHasher
.hash_one
(
item
);
result
^=
item_hash
;
}
state
.write_u64
(
result
);
}
}
impl
<
T
>
TaskInput
for
HashableIndexSet
<
T
>
where
T
:
TaskInput
,
{
fn
is_resolved
(
&
self
)
->
bool
{
self
.iter
()
.all
(
TaskInput
::
is_resolved
)
}
fn
is_transient
(
&
self
)
->
bool
{
self
.iter
()
.any
(
TaskInput
::
is_transient
)
}
async
fn
resolve_input
(
&
self
)
->
Result
<
Self
>
{
let
mut
resolved
=
FxIndexSet
::
with_capacity_and_hasher
(
self
.len
(),
Default
::
default
());
for
value
in
self
.iter
()
{
resolved
.insert
(
value
.resolve_input
()
.await
?
);
}
Ok
(
HashableIndexSet
(
resolved
))
}
}
unsafe
impl
<
T
:
NonLocalValue
+
Hash
+
Eq
+
Decode
<
()
>
+
Encode
>
NonLocalValue
for
HashableIndexSet
<
T
>
{
}
turbopack/crates/turbopack-cli/src/build/mod.rs
View file @
95e991e0
...
...
@@ -476,7 +476,11 @@ async fn build_internal(
.unwrap
(),
)
?
.with_extension
(
"entry.js"
),
ChunkGroup
::
Entry
(
vec!
[
ResolvedVc
::
upcast
(
ecmascript
)]),
ChunkGroup
::
Entry
(
[
ResolvedVc
::
upcast
(
ecmascript
)]
.into_iter
()
.collect
(),
),
module_graph
,
OutputAssets
::
empty
(),
OutputAssets
::
empty
(),
...
...
turbopack/crates/turbopack-core/src/module_graph/chunk_group_info.rs
View file @
95e991e0
This diff is collapsed.
Click to expand it.
turbopack/crates/turbopack-dev-server/src/html.rs
View file @
95e991e0
...
...
@@ -170,7 +170,9 @@ impl DevHtmlAsset {
chunking_context
.root_chunk_group_assets
(
chunkable_module
.ident
(),
ChunkGroup
::
Entry
(
vec!
[
ResolvedVc
::
upcast
(
chunkable_module
)]),
ChunkGroup
::
Entry
(
[
ResolvedVc
::
upcast
(
chunkable_module
)]
.into_iter
()
.collect
(),
),
*
module_graph
,
)
.await
?
...
...
turbopack/crates/turbopack-node/src/transforms/webpack.rs
View file @
95e991e0
...
...
@@ -726,7 +726,7 @@ impl EvaluateContext for WebpackLoaderContext {
let
bootstrap
=
self
.chunking_context
.root_entry_chunk_group_asset
(
entry_path
.clone
(),
ChunkGroup
::
Entry
(
vec!
[
ResolvedVc
::
upcast
(
evaluatable
)]
),
ChunkGroup
::
Entry
(
[
ResolvedVc
::
upcast
(
evaluatable
)]
.into_iter
()
.collect
()
),
*
import_module_graph
,
OutputAssets
::
empty
(),
OutputAssets
::
empty
(),
...
...
turbopack/crates/turbopack-tests/tests/snapshot.rs
View file @
95e991e0
...
...
@@ -603,7 +603,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
chunk_root_path
.join
(
entry_module
.ident
()
.path
()
.await
?
.file_stem
()
.unwrap
())
?
.with_extension
(
"entry.js"
),
ChunkGroup
::
Entry
(
entry_modules
),
ChunkGroup
::
Entry
(
entry_modules
.into_iter
()
.collect
()
),
module_graph
,
OutputAssets
::
empty
(),
OutputAssets
::
empty
(),
...
...
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