diff --git a/crates/next-core/src/next_app/app_client_references_chunks.rs b/crates/next-core/src/next_app/app_client_references_chunks.rs index 4f70ca74b5c0f..98cac23cd50f6 100644 --- a/crates/next-core/src/next_app/app_client_references_chunks.rs +++ b/crates/next-core/src/next_app/app_client_references_chunks.rs @@ -169,6 +169,8 @@ pub async fn get_app_client_references_chunks( list.extend(framework_reference_types); } + let chunk_group_info = module_graph.chunk_group_info(); + let mut current_client_availability_info = client_availability_info.into_value(); let mut current_client_chunks = OutputAssets::empty().to_resolved().await?; let mut current_ssr_availability_info = AvailabilityInfo::Root; @@ -181,6 +183,12 @@ pub async fn get_app_client_references_chunks( for (server_component, client_reference_types) in client_references_by_server_component.into_iter() { + let parent_chunk_group = *chunk_group_info + .get_index_of(ChunkGroup::Shared(ResolvedVc::upcast( + server_component.await?.module, + ))) + .await?; + let base_ident = server_component.ident(); let server_path = server_component.server_path(); @@ -217,9 +225,8 @@ pub async fn get_app_client_references_chunks( ssr_chunking_context.chunk_group( base_ident.with_modifier(ssr_modules_modifier()), - // TODO use correct parameters here, and sort the modules? ChunkGroup::IsolatedMerged { - parent: 0, + parent: parent_chunk_group, merge_tag: ECMASCRIPT_CLIENT_REFERENCE_MERGE_TAG_SSR.clone(), entries: ssr_modules, }, @@ -256,9 +263,8 @@ pub async fn get_app_client_references_chunks( Some(client_chunking_context.chunk_group( base_ident.with_modifier(client_modules_modifier()), - // TODO use correct parameters here, and sort the modules? ChunkGroup::IsolatedMerged { - parent: 0, + parent: parent_chunk_group, merge_tag: ECMASCRIPT_CLIENT_REFERENCE_MERGE_TAG_CLIENT.clone(), entries: client_modules, }, diff --git a/turbopack/crates/turbopack-core/src/module_graph/chunk_group_info.rs b/turbopack/crates/turbopack-core/src/module_graph/chunk_group_info.rs index 4bb374d329dcf..dd349ab24546e 100644 --- a/turbopack/crates/turbopack-core/src/module_graph/chunk_group_info.rs +++ b/turbopack/crates/turbopack-core/src/module_graph/chunk_group_info.rs @@ -4,7 +4,7 @@ use std::{ ops::{Deref, DerefMut}, }; -use anyhow::Result; +use anyhow::{bail, Result}; use either::Either; use indexmap::map::Entry; use petgraph::graph::{DiGraph, EdgeIndex, NodeIndex}; @@ -88,7 +88,19 @@ impl Hash for RoaringBitmapWrapper { pub struct ChunkGroupInfo { pub module_chunk_groups: FxHashMap>, RoaringBitmapWrapper>, #[turbo_tasks(trace_ignore)] - pub chunk_groups: Vec, + pub chunk_groups: FxIndexSet, +} + +#[turbo_tasks::value_impl] +impl ChunkGroupInfo { + #[turbo_tasks::function] + pub fn get_index_of(&self, chunk_group: ChunkGroup) -> Result> { + if let Some(idx) = self.chunk_groups.get_index_of(&chunk_group) { + Ok(Vc::cell(idx)) + } else { + bail!("Couldn't find chunk group index"); + } + } } #[derive(Debug, Clone, Hash, TaskInput, PartialEq, Eq, Serialize, Deserialize)]