From 43e8062b96b17cb404135b0a85831ac43742a3d8 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:02:59 +0100 Subject: [PATCH 1/2] Only inherit visited modules from parent layouts --- crates/next-api/src/module_graph.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/next-api/src/module_graph.rs b/crates/next-api/src/module_graph.rs index b8bb28aa1b593..06ff26f61e0d9 100644 --- a/crates/next-api/src/module_graph.rs +++ b/crates/next-api/src/module_graph.rs @@ -588,22 +588,24 @@ async fn get_module_graph_for_endpoint( }; // ast-grep-ignore: to-resolved-in-loop - for module in server_component_entries - .iter() - .map(|m| ResolvedVc::upcast::>(*m)) - { + for module in server_component_entries.iter() { let graph = SingleModuleGraph::new_with_entries_visited( *entry, - vec![*module], + vec![Vc::upcast(**module)], Vc::cell(visited_modules.clone()), ) .to_resolved() .await?; - visited_modules.extend(graph.await?.iter_nodes().map(|n| n.module)); graphs.push(graph); + let is_layout = module.server_path().file_stem().await?.as_deref() == Some("layout"); + if is_layout { + // Only propagate the visited_modules of the parent layout(s), not across siblings such + // as loading.js and page.js. + visited_modules.extend(graph.await?.iter_nodes().map(|n| n.module)); + } } - // The previous iterations above (might) have added the entry node, but not actually visited it. + // Any previous iteration above would have added the entry node, but not actually visited it. visited_modules.remove(&entry); let graph = SingleModuleGraph::new_with_entries_visited( *entry, From afe0d22678e07fb04dfbcddc80ad6926e83c834d Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:03:28 +0100 Subject: [PATCH 2/2] Reenable single-graph client reference collection --- crates/next-api/src/app.rs | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/crates/next-api/src/app.rs b/crates/next-api/src/app.rs index 46a8c2b16b2e7..fc97c77c4e8dc 100644 --- a/crates/next-api/src/app.rs +++ b/crates/next-api/src/app.rs @@ -18,10 +18,7 @@ use next_core::{ get_client_module_options_context, get_client_resolve_options_context, get_client_runtime_entries, ClientContextType, RuntimeEntries, }, - next_client_reference::{ - client_reference_graph, find_server_entries, ClientReferenceGraphResult, - NextEcmascriptClientReferenceTransition, ServerEntries, VisitedClientReferenceGraphNodes, - }, + next_client_reference::{ClientReferenceGraphResult, NextEcmascriptClientReferenceTransition}, next_config::NextConfig, next_dynamic::NextDynamicTransition, next_edge::route_regex::get_named_middleware_regex, @@ -957,36 +954,8 @@ impl AppEndpoint { .get_next_dynamic_imports_for_endpoint(*rsc_entry) .await?; - let client_references_old = { - let ServerEntries { - server_component_entries, - server_utils, - } = &*find_server_entries(*rsc_entry).await?; - - let mut client_references = client_reference_graph( - server_utils.iter().map(|&v| *v).collect(), - VisitedClientReferenceGraphNodes::empty(), - ) - .await? - .clone_value(); - - for module in server_component_entries - .iter() - .map(|m| ResolvedVc::upcast::>(*m)) - .chain(std::iter::once(rsc_entry)) - { - let current_client_references = - client_reference_graph(vec![*module], *client_references.visited_nodes) - .await?; - - client_references.extend(¤t_client_references); - } - client_references - }; - let client_references_cell = client_references_old.cell(); - // TODO revert this once client references shared between layout segments work. - // let client_references_cell = - // reduced_graphs.get_client_references_for_endpoint(*rsc_entry); + let client_references_cell = + reduced_graphs.get_client_references_for_endpoint(*rsc_entry); let client_references_chunks = get_app_client_references_chunks( client_references_cell,