Unverified Commit fda324e2 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: correctly use ChunkGroup::Shared (#90978)

I don't think we have any tests that the server utility chunking actually works.
But I can't actually properly remember why we added it in the first place: https://github.com/vercel/next.js/pull/70461
parent 60f903c7
...@@ -1799,11 +1799,7 @@ impl AppEndpoint { ...@@ -1799,11 +1799,7 @@ impl AppEndpoint {
NextRuntime::Edge => { NextRuntime::Edge => {
let chunk_group1 = chunking_context.chunk_group( let chunk_group1 = chunking_context.chunk_group(
server_action_manifest_loader.ident(), server_action_manifest_loader.ident(),
ChunkGroup::Entry( ChunkGroup::Shared(ResolvedVc::upcast(server_action_manifest_loader)),
[ResolvedVc::upcast(server_action_manifest_loader)]
.into_iter()
.collect(),
),
module_graph, module_graph,
AvailabilityInfo::root(), AvailabilityInfo::root(),
); );
...@@ -1823,9 +1819,20 @@ impl AppEndpoint { ...@@ -1823,9 +1819,20 @@ impl AppEndpoint {
async { async {
let mut current_chunk_group = ChunkGroupResult::empty_resolved(); let mut current_chunk_group = ChunkGroupResult::empty_resolved();
let entry_chunk_group = ChunkGroup::Entry(vec![app_entry.rsc_entry]);
let chunk_group_info = module_graph.chunk_group_info();
let client_references = client_references.await?; let client_references = client_references.await?;
let span = tracing::trace_span!("server utils"); let span = tracing::trace_span!("server utils");
async { async {
let parent_chunk_group = *chunk_group_info
.get_index_of(entry_chunk_group.clone())
.await?;
// This is basically a manual shared chunk. But it's particularly helpful
// for development, so that we share more layout segment chunks across
// pages.
let server_utils = client_references let server_utils = client_references
.server_utils .server_utils
.iter() .iter()
...@@ -1838,8 +1845,11 @@ impl AppEndpoint { ...@@ -1838,8 +1845,11 @@ impl AppEndpoint {
this.app_project.project().project_path().owned().await?, this.app_project.project().project_path().owned().await?,
) )
.with_modifier(rcstr!("server-utils")), .with_modifier(rcstr!("server-utils")),
// TODO this should be ChunkGroup::Shared ChunkGroup::SharedMerged {
ChunkGroup::Entry(server_utils), merge_tag: NEXT_SERVER_UTILITY_MERGE_TAG.clone(),
entries: server_utils,
parent: parent_chunk_group,
},
module_graph, module_graph,
AvailabilityInfo::root(), AvailabilityInfo::root(),
) )
...@@ -1870,10 +1880,9 @@ impl AppEndpoint { ...@@ -1870,10 +1880,9 @@ impl AppEndpoint {
async { async {
let chunk_group = chunking_context.chunk_group( let chunk_group = chunking_context.chunk_group(
server_component.ident(), server_component.ident(),
// TODO this should be ChunkGroup::Shared ChunkGroup::Shared(ResolvedVc::upcast(
ChunkGroup::Entry(vec![ResolvedVc::upcast(
server_component.await?.module, server_component.await?.module,
)]), )),
module_graph, module_graph,
current_chunk_group.await?.availability_info, current_chunk_group.await?.availability_info,
); );
...@@ -1892,9 +1901,7 @@ impl AppEndpoint { ...@@ -1892,9 +1901,7 @@ impl AppEndpoint {
{ {
let chunk_group = chunking_context.chunk_group( let chunk_group = chunking_context.chunk_group(
server_action_manifest_loader.ident(), server_action_manifest_loader.ident(),
ChunkGroup::Entry(vec![ResolvedVc::upcast( ChunkGroup::Shared(ResolvedVc::upcast(server_action_manifest_loader)),
server_action_manifest_loader,
)]),
module_graph, module_graph,
current_chunk_group.await?.availability_info, current_chunk_group.await?.availability_info,
); );
...@@ -1919,7 +1926,7 @@ impl AppEndpoint { ...@@ -1919,7 +1926,7 @@ impl AppEndpoint {
"app{original_name}.js", "app{original_name}.js",
original_name = app_entry.original_name original_name = app_entry.original_name
))?, ))?,
ChunkGroup::Entry(vec![app_entry.rsc_entry]), entry_chunk_group,
module_graph, module_graph,
*current_chunks, *current_chunks,
current_referenced_assets, current_referenced_assets,
......
...@@ -122,25 +122,20 @@ impl ChunkGroupInfo { ...@@ -122,25 +122,20 @@ impl ChunkGroupInfo {
} }
} }
/// See [ChunkGroup] for documentation
#[derive( #[derive(
Debug, Clone, Hash, TaskInput, PartialEq, Eq, TraceRawVcs, NonLocalValue, Encode, Decode, Debug, Clone, Hash, TaskInput, PartialEq, Eq, TraceRawVcs, NonLocalValue, Encode, Decode,
)] )]
pub enum ChunkGroupEntry { pub enum ChunkGroupEntry {
/// e.g. a page
Entry(Vec<ResolvedVc<Box<dyn Module>>>), Entry(Vec<ResolvedVc<Box<dyn Module>>>),
/// a module with an incoming async edge
Async(ResolvedVc<Box<dyn Module>>), Async(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming non-merged isolated edge
Isolated(ResolvedVc<Box<dyn Module>>), Isolated(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming merging isolated edge
IsolatedMerged { IsolatedMerged {
parent: Box<ChunkGroupEntry>, parent: Box<ChunkGroupEntry>,
merge_tag: RcStr, merge_tag: RcStr,
entries: Vec<ResolvedVc<Box<dyn Module>>>, entries: Vec<ResolvedVc<Box<dyn Module>>>,
}, },
/// a module with an incoming non-merging shared edge
Shared(ResolvedVc<Box<dyn Module>>), Shared(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming merging shared edge
SharedMerged { SharedMerged {
parent: Box<ChunkGroupEntry>, parent: Box<ChunkGroupEntry>,
merge_tag: RcStr, merge_tag: RcStr,
...@@ -162,21 +157,26 @@ impl ChunkGroupEntry { ...@@ -162,21 +157,26 @@ impl ChunkGroupEntry {
#[derive(Debug, Clone, Hash, TaskInput, PartialEq, Eq, TraceRawVcs, Encode, Decode)] #[derive(Debug, Clone, Hash, TaskInput, PartialEq, Eq, TraceRawVcs, Encode, Decode)]
pub enum ChunkGroup { pub enum ChunkGroup {
/// e.g. a page /// The entry chunk group of the compilation, e.g. src/index.js for a SPA, or app/foo/page.js
/// for Next.js.
Entry(Vec<ResolvedVc<Box<dyn Module>>>), Entry(Vec<ResolvedVc<Box<dyn Module>>>),
/// a module with an incoming async edge /// An async chunk group. Corresponds to an incoming [ChunkingType::Async] reference
Async(ResolvedVc<Box<dyn Module>>), Async(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming non-merged isolated edge /// An isolated chunk group. Corresponds to an incoming [ChunkingType::Isolated] reference with
/// `merge_tag: None`
Isolated(ResolvedVc<Box<dyn Module>>), Isolated(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming merging isolated edge /// An isolated chunk group. Corresponds to an incoming [ChunkingType::Isolated] reference with
/// `merge_tag: Some(_)`
IsolatedMerged { IsolatedMerged {
parent: usize, parent: usize,
merge_tag: RcStr, merge_tag: RcStr,
entries: Vec<ResolvedVc<Box<dyn Module>>>, entries: Vec<ResolvedVc<Box<dyn Module>>>,
}, },
/// a module with an incoming non-merging shared edge /// A shared chunk group. Corresponds to an incoming [ChunkingType::Shared] reference with
/// `merge_tag: None`
Shared(ResolvedVc<Box<dyn Module>>), Shared(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming merging shared edge /// A shared chunk group. Corresponds to an incoming [ChunkingType::Shared] reference with
/// `merge_tag: Some(_)`
SharedMerged { SharedMerged {
parent: usize, parent: usize,
merge_tag: RcStr, merge_tag: RcStr,
...@@ -275,22 +275,17 @@ impl ChunkGroup { ...@@ -275,22 +275,17 @@ impl ChunkGroup {
} }
} }
/// See [ChunkGroup] for documentation
#[derive(Debug, Clone, Hash, PartialEq, Eq, Encode, Decode)] #[derive(Debug, Clone, Hash, PartialEq, Eq, Encode, Decode)]
pub enum ChunkGroupKey { pub enum ChunkGroupKey {
/// e.g. a page
Entry(Vec<ResolvedVc<Box<dyn Module>>>), Entry(Vec<ResolvedVc<Box<dyn Module>>>),
/// a module with an incoming async edge
Async(ResolvedVc<Box<dyn Module>>), Async(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming non-merging isolated edge
Isolated(ResolvedVc<Box<dyn Module>>), Isolated(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming merging isolated edge
IsolatedMerged { IsolatedMerged {
parent: ChunkGroupId, parent: ChunkGroupId,
merge_tag: RcStr, merge_tag: RcStr,
}, },
/// a module with an incoming non-merging shared edge
Shared(ResolvedVc<Box<dyn Module>>), Shared(ResolvedVc<Box<dyn Module>>),
/// a module with an incoming merging shared edge
SharedMerged { SharedMerged {
parent: ChunkGroupId, parent: ChunkGroupId,
merge_tag: RcStr, merge_tag: RcStr,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment