Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack: only inherit visited modules from parent layouts #74072

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 3 additions & 34 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Box<dyn Module>>(*m))
.chain(std::iter::once(rsc_entry))
{
let current_client_references =
client_reference_graph(vec![*module], *client_references.visited_nodes)
.await?;

client_references.extend(&current_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,
Expand Down
16 changes: 9 additions & 7 deletions crates/next-api/src/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Box<dyn Module>>(*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,
Expand Down
Loading