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
c8ac0bdd
Unverified
Commit
c8ac0bdd
authored
Feb 20, 2025
by
Tobias Koppers
Committed by
GitHub
Feb 20, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Turbopack] add ChunkingType::Shared (#76228)
### What? use ChunkingType::Shared for server utils and components
parent
8f346de9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
100 additions
and
12 deletions
+100
-12
server_component_reference.rs
...e/src/next_server_component/server_component_reference.rs
+12
-2
server_utility_reference.rs
...-core/src/next_server_utility/server_utility_reference.rs
+12
-2
chunk_group.rs
turbopack/crates/turbopack-core/src/chunk/chunk_group.rs
+3
-1
mod.rs
turbopack/crates/turbopack-core/src/chunk/mod.rs
+8
-0
utils.rs
turbopack/crates/turbopack-core/src/introspect/utils.rs
+6
-0
async_module_info.rs
...ates/turbopack-core/src/module_graph/async_module_info.rs
+10
-2
chunk_group_info.rs
...rates/turbopack-core/src/module_graph/chunk_group_info.rs
+49
-5
No files found.
crates/next-core/src/next_server_component/server_component_reference.rs
View file @
c8ac0bdd
...
...
@@ -2,7 +2,9 @@ use anyhow::Result;
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks
::{
ResolvedVc
,
ValueToString
,
Vc
};
use
turbopack_core
::{
chunk
::
ChunkableModuleReference
,
module
::
Module
,
reference
::
ModuleReference
,
chunk
::{
ChunkableModuleReference
,
ChunkingType
,
ChunkingTypeOption
},
module
::
Module
,
reference
::
ModuleReference
,
resolve
::
ModuleResolveResult
,
};
...
...
@@ -42,4 +44,12 @@ impl ModuleReference for NextServerComponentModuleReference {
}
#[turbo_tasks
::
value_impl]
impl
ChunkableModuleReference
for
NextServerComponentModuleReference
{}
impl
ChunkableModuleReference
for
NextServerComponentModuleReference
{
#[turbo_tasks
::
function]
fn
chunking_type
(
&
self
)
->
Vc
<
ChunkingTypeOption
>
{
Vc
::
cell
(
Some
(
ChunkingType
::
Shared
{
inherit_async
:
true
,
merge_tag
:
None
,
}))
}
}
crates/next-core/src/next_server_utility/server_utility_reference.rs
View file @
c8ac0bdd
...
...
@@ -2,7 +2,9 @@ use anyhow::Result;
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks
::{
ResolvedVc
,
ValueToString
,
Vc
};
use
turbopack_core
::{
chunk
::
ChunkableModuleReference
,
module
::
Module
,
reference
::
ModuleReference
,
chunk
::{
ChunkableModuleReference
,
ChunkingType
,
ChunkingTypeOption
},
module
::
Module
,
reference
::
ModuleReference
,
resolve
::
ModuleResolveResult
,
};
...
...
@@ -42,4 +44,12 @@ impl ModuleReference for NextServerUtilityModuleReference {
}
#[turbo_tasks
::
value_impl]
impl
ChunkableModuleReference
for
NextServerUtilityModuleReference
{}
impl
ChunkableModuleReference
for
NextServerUtilityModuleReference
{
#[turbo_tasks
::
function]
fn
chunking_type
(
&
self
)
->
Vc
<
ChunkingTypeOption
>
{
Vc
::
cell
(
Some
(
ChunkingType
::
Shared
{
inherit_async
:
true
,
merge_tag
:
Some
(
"next-server-utility"
.into
()),
}))
}
}
turbopack/crates/turbopack-core/src/chunk/chunk_group.rs
View file @
c8ac0bdd
...
...
@@ -242,7 +242,9 @@ pub async fn chunk_group_content(
};
Ok
(
match
edge
{
ChunkingType
::
Parallel
|
ChunkingType
::
ParallelInheritAsync
=>
{
ChunkingType
::
Parallel
|
ChunkingType
::
ParallelInheritAsync
|
ChunkingType
::
Shared
{
..
}
=>
{
if
is_available
{
GraphTraversalAction
::
Skip
}
else
{
...
...
turbopack/crates/turbopack-core/src/chunk/mod.rs
View file @
c8ac0bdd
...
...
@@ -168,6 +168,7 @@ pub enum ChunkingType {
Parallel
,
/// Module is placed in the same chunk group and is loaded in parallel. It
/// becomes an async module when the referenced module is async.
// TODO make inherit_async a separate field
ParallelInheritAsync
,
/// An async loader is placed into the referencing chunk and loads the
/// separate chunk group in which the module is placed.
...
...
@@ -179,6 +180,13 @@ pub enum ChunkingType {
_ty
:
ChunkGroupType
,
merge_tag
:
Option
<
RcStr
>
,
},
/// Create a new chunk group in a separate context, merging references with the same tag into a
/// single chunk group. It provides available modules to the current chunk group. It's assumed
/// to be loaded before the current chunk group.
Shared
{
inherit_async
:
bool
,
merge_tag
:
Option
<
RcStr
>
,
},
// Module not placed in chunk group, but its references are still followed.
Traced
,
}
...
...
turbopack/crates/turbopack-core/src/introspect/utils.rs
View file @
c8ac0bdd
...
...
@@ -38,6 +38,11 @@ fn isolated_reference_ty() -> Vc<RcStr> {
Vc
::
cell
(
"isolated reference"
.into
())
}
#[turbo_tasks
::
function]
fn
shared_reference_ty
()
->
Vc
<
RcStr
>
{
Vc
::
cell
(
"shared reference"
.into
())
}
#[turbo_tasks
::
function]
fn
traced_reference_ty
()
->
Vc
<
RcStr
>
{
Vc
::
cell
(
"traced reference"
.into
())
...
...
@@ -82,6 +87,7 @@ pub async fn children_from_module_references(
}
Some
(
ChunkingType
::
Async
)
=>
key
=
async_reference_ty
(),
Some
(
ChunkingType
::
Isolated
{
..
})
=>
key
=
isolated_reference_ty
(),
Some
(
ChunkingType
::
Shared
{
..
})
=>
key
=
shared_reference_ty
(),
Some
(
ChunkingType
::
Traced
)
=>
key
=
traced_reference_ty
(),
}
}
...
...
turbopack/crates/turbopack-core/src/module_graph/async_module_info.rs
View file @
c8ac0bdd
...
...
@@ -88,7 +88,11 @@ async fn compute_async_module_info_single(
// edges.push((parent_module, module, async_modules.contains(&module)));
match
chunking_type
{
ChunkingType
::
ParallelInheritAsync
=>
{
ChunkingType
::
ParallelInheritAsync
|
ChunkingType
::
Shared
{
inherit_async
:
true
,
..
}
=>
{
if
async_modules
.contains
(
&
module
)
{
async_modules
.insert
(
parent_module
);
}
...
...
@@ -96,7 +100,11 @@ async fn compute_async_module_info_single(
ChunkingType
::
Parallel
|
ChunkingType
::
Async
|
ChunkingType
::
Isolated
{
..
}
|
ChunkingType
::
Traced
=>
{
|
ChunkingType
::
Traced
|
ChunkingType
::
Shared
{
inherit_async
:
false
,
..
}
=>
{
// Nothing to propagate
}
}
...
...
turbopack/crates/turbopack-core/src/module_graph/chunk_group_info.rs
View file @
c8ac0bdd
...
...
@@ -107,15 +107,25 @@ pub enum ChunkGroup {
merge_tag
:
RcStr
,
entries
:
Vec
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
},
/// a module with an incoming non-merging shared edge
Shared
(
ResolvedVc
<
Box
<
dyn
Module
>>
),
/// a module with an incoming merging shared edge
SharedMerged
{
parent
:
usize
,
merge_tag
:
RcStr
,
entries
:
Vec
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
},
}
impl
ChunkGroup
{
pub
fn
entries
(
&
self
)
->
impl
Iterator
<
Item
=
ResolvedVc
<
Box
<
dyn
Module
>>>
+
'_
{
match
self
{
ChunkGroup
::
Entry
(
e
)
|
ChunkGroup
::
Async
(
e
)
|
ChunkGroup
::
Isolated
(
e
)
=>
{
Either
::
Left
(
std
::
iter
::
once
(
*
e
))
}
ChunkGroup
::
IsolatedMerged
{
entries
,
..
}
=>
Either
::
Right
(
entries
.iter
()
.copied
()),
ChunkGroup
::
Entry
(
e
)
|
ChunkGroup
::
Async
(
e
)
|
ChunkGroup
::
Isolated
(
e
)
|
ChunkGroup
::
Shared
(
e
)
=>
Either
::
Left
(
std
::
iter
::
once
(
*
e
)),
ChunkGroup
::
IsolatedMerged
{
entries
,
..
}
|
ChunkGroup
::
SharedMerged
{
entries
,
..
}
=>
Either
::
Right
(
entries
.iter
()
.copied
()),
}
}
}
...
...
@@ -133,6 +143,13 @@ enum ChunkGroupKey {
parent
:
ChunkGroupId
,
merge_tag
:
RcStr
,
},
/// a module with an incoming merging shared edge
Shared
(
ResolvedVc
<
Box
<
dyn
Module
>>
),
/// a module with an incoming merging shared edge
SharedMerged
{
parent
:
ChunkGroupId
,
merge_tag
:
RcStr
,
},
}
#[derive(Debug,
Copy,
Clone,
PartialEq,
Eq,
Hash,
Serialize,
Deserialize)]
...
...
@@ -253,6 +270,11 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
}
=>
ChunkGroupInheritance
::
ChunkGroup
(
Either
::
Left
(
std
::
iter
::
once
(
ChunkGroupKey
::
Isolated
(
node
.module
),
))),
ChunkingType
::
Shared
{
merge_tag
:
None
,
..
}
=>
ChunkGroupInheritance
::
ChunkGroup
(
Either
::
Left
(
std
::
iter
::
once
(
ChunkGroupKey
::
Shared
(
node
.module
),
))),
ChunkingType
::
Isolated
{
merge_tag
:
Some
(
merge_tag
),
..
...
...
@@ -263,7 +285,23 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
parent
:
ChunkGroupId
(
parent
),
merge_tag
:
merge_tag
.clone
(),
});
ChunkGroupInheritance
::
ChunkGroup
(
Either
::
Right
(
chunk_groups
))
ChunkGroupInheritance
::
ChunkGroup
(
Either
::
Right
(
Either
::
Left
(
chunk_groups
,
)))
}
ChunkingType
::
Shared
{
merge_tag
:
Some
(
merge_tag
),
..
}
=>
{
let
parents
=
module_chunk_groups
.get
(
&
parent
.module
)
.unwrap
();
let
chunk_groups
=
parents
.iter
()
.map
(|
parent
|
ChunkGroupKey
::
SharedMerged
{
parent
:
ChunkGroupId
(
parent
),
merge_tag
:
merge_tag
.clone
(),
});
ChunkGroupInheritance
::
ChunkGroup
(
Either
::
Right
(
Either
::
Right
(
chunk_groups
,
)))
}
ChunkingType
::
Traced
=>
{
// Traced modules are not placed in chunk groups
...
...
@@ -422,6 +460,12 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
entries
:
isolated_merged_entries
.into_iter
()
.collect
(),
}
}
ChunkGroupKey
::
Shared
(
module
)
=>
ChunkGroup
::
Shared
(
module
),
ChunkGroupKey
::
SharedMerged
{
parent
,
merge_tag
}
=>
ChunkGroup
::
SharedMerged
{
parent
:
parent
.
0
as
usize
,
merge_tag
,
entries
:
isolated_merged_entries
.into_iter
()
.collect
(),
},
})
.collect
(),
}
...
...
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