From d3f5611bc06e1deb3b54e5071b4194e87ee8b5ff Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:39:47 +0100 Subject: [PATCH] Fix pages router --- crates/next-api/src/module_graph.rs | 41 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/crates/next-api/src/module_graph.rs b/crates/next-api/src/module_graph.rs index e6d5b1dea6b27f..b4235985e2da91 100644 --- a/crates/next-api/src/module_graph.rs +++ b/crates/next-api/src/module_graph.rs @@ -423,21 +423,27 @@ async fn get_module_graph_for_endpoint( server_component_entries, } = &*find_server_entries(*entry).await?; - let graph = SingleModuleGraph::new_with_entries_visited( - *entry, - server_utils.iter().map(|m| **m).collect(), - Vc::cell(Default::default()), - ) - .to_resolved() - .await?; - let mut visited_modules: HashSet<_> = graph - .await? - .graph - .node_weights() - .map(|n| n.module) - .collect(); - - let mut graphs = vec![graph]; + let mut graphs = vec![]; + + let mut visited_modules = if !server_utils.is_empty() { + let graph = SingleModuleGraph::new_with_entries_visited( + *entry, + server_utils.iter().map(|m| **m).collect(), + Vc::cell(Default::default()), + ) + .to_resolved() + .await?; + graphs.push(graph); + graph + .await? + .iter_nodes() + .map(|n| n.module) + .collect::>() + } else { + HashSet::new() + }; + + // ast-grep-ignore: to-resolved-in-loop for module in server_component_entries .iter() .map(|m| ResolvedVc::upcast::>(*m)) @@ -449,9 +455,12 @@ async fn get_module_graph_for_endpoint( ) .to_resolved() .await?; - visited_modules.extend(graph.await?.graph.node_weights().map(|n| n.module)); + visited_modules.extend(graph.await?.iter_nodes().map(|n| n.module)); graphs.push(graph); } + + // The previous iterations above (might) have added the entry node, but not actually visited it. + visited_modules.remove(&entry); let graph = SingleModuleGraph::new_with_entries_visited( *entry, vec![*entry],