diff --git a/crates/next-core/src/next_client_reference/visit_client_reference.rs b/crates/next-core/src/next_client_reference/visit_client_reference.rs index b34ccd19de6a7..a2cc40f77c8cf 100644 --- a/crates/next-core/src/next_client_reference/visit_client_reference.rs +++ b/crates/next-core/src/next_client_reference/visit_client_reference.rs @@ -149,8 +149,11 @@ pub async fn client_reference_graph( server_component: *server_component, } } else { - VisitClientReferenceNodeState::Entry { - entry_path: module.ident().path().resolve().await?, + let entry_path = module.ident().path().resolve().await?; + if entry_path.await?.file_name() == "edge-wrapper.js" { + VisitClientReferenceNodeState::EdgeEntry { entry_path } + } else { + VisitClientReferenceNodeState::Entry { entry_path } } }, ty: VisitClientReferenceNodeType::Internal( @@ -221,13 +224,16 @@ pub struct ServerEntries { #[turbo_tasks::function] pub async fn find_server_entries(entry: ResolvedVc>) -> Result> { + let entry_path = entry.ident().path().resolve().await?; let graph = AdjacencyMap::new() .skip_duplicates() .visit( vec![VisitClientReferenceNode { state: { - VisitClientReferenceNodeState::Entry { - entry_path: entry.ident().path().resolve().await?, + if entry_path.await?.file_name() == "edge-wrapper.js" { + VisitClientReferenceNodeState::EdgeEntry { entry_path } + } else { + VisitClientReferenceNodeState::Entry { entry_path } } }, ty: VisitClientReferenceNodeType::Internal(entry, entry.ident().to_string().await?), @@ -279,6 +285,9 @@ struct VisitClientReferenceNode { Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize, Debug, ValueDebugFormat, TraceRawVcs, )] enum VisitClientReferenceNodeState { + EdgeEntry { + entry_path: Vc, + }, Entry { entry_path: Vc, }, @@ -290,6 +299,7 @@ enum VisitClientReferenceNodeState { impl VisitClientReferenceNodeState { fn server_component(&self) -> Option> { match self { + VisitClientReferenceNodeState::EdgeEntry { .. } => None, VisitClientReferenceNodeState::Entry { .. } => None, VisitClientReferenceNodeState::InServerComponent { server_component } => { Some(*server_component) @@ -412,6 +422,29 @@ impl Visit for VisitClientReference { }); } + // TODO have a cleaner way to check for template modules + // e.g. edge-wrapper.js -> edge-ssr-app.js -> app-page.js + + // Skip over edge-wrapper.js -> edge-ssr-app.js and properly detect server utils + if let VisitClientReferenceNodeState::EdgeEntry { entry_path } = &node.state { + let module_path = module.ident().path().resolve().await?; + let module_path_ref = &module_path.await?.path; + if module_path != *entry_path + && !module_path_ref + .ends_with("next/dist/esm/build/templates/edge-ssr-app.js") + { + return Ok(VisitClientReferenceNode { + state: VisitClientReferenceNodeState::Entry { + entry_path: module_path, + }, + ty: VisitClientReferenceNodeType::Internal( + module, + module.ident().to_string().await?, + ), + }); + } + } + if let VisitClientReferenceNodeState::Entry { entry_path } = &node.state { if module.ident().path().resolve().await? != *entry_path { return Ok(VisitClientReferenceNode {