Skip to content
Draft
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
4 changes: 2 additions & 2 deletions crates/next-api/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ pub async fn analyze_module_graphs(module_graphs: Vc<ModuleGraphs>) -> Result<Vc
let mut all_modules = FxIndexSet::default();
let mut all_edges = FxIndexSet::default();
let mut all_async_edges = FxIndexSet::default();
for &module_graph in module_graphs.await? {
let module_graph = module_graph.await?;
for module_graph in module_graphs.await?.iter() {
let module_graph = module_graph.connect().await?;
module_graph.traverse_edges_unordered(|parent, node| {
if let Some((parent_node, reference)) = parent {
all_modules.insert(parent_node);
Expand Down
31 changes: 18 additions & 13 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ impl AppProject {
};

Ok(BaseAndFullModuleGraph {
base: base.connect().to_resolved().await?,
full: full.connect().to_resolved().await?,
base,
full,
binding_usage_info,
}
.cell())
Expand Down Expand Up @@ -1274,7 +1274,7 @@ impl AppEndpoint {
AssetIdent::from_path(project.project_path().owned().await?)
.with_modifier(rcstr!("client-shared-chunks")),
this.app_project.client_runtime_entries(),
*module_graphs.full,
module_graphs.full.connect(),
*client_chunking_context,
);

Expand All @@ -1292,14 +1292,14 @@ impl AppEndpoint {
let per_page_module_graph = *project.per_page_module_graph().await?;

let next_dynamic_imports =
NextDynamicGraphs::new(*module_graphs.base, per_page_module_graph)
NextDynamicGraphs::new(module_graphs.base.connect(), per_page_module_graph)
.get_next_dynamic_imports_for_endpoint(*rsc_entry)
.await?;

let is_production = project.next_mode().await?.is_production();

let client_references =
ClientReferencesGraphs::new(*module_graphs.base, per_page_module_graph)
ClientReferencesGraphs::new(module_graphs.base.connect(), per_page_module_graph)
.get_client_references_for_endpoint(
*rsc_entry,
matches!(this.ty, AppEndpointType::Page { .. }),
Expand All @@ -1311,7 +1311,7 @@ impl AppEndpoint {

let client_references_chunks = get_app_client_references_chunks(
*client_references,
*module_graphs.full,
module_graphs.full.connect(),
*client_chunking_context,
availability_info,
ssr_chunking_context.map(|ctx| *ctx),
Expand Down Expand Up @@ -1387,7 +1387,7 @@ impl AppEndpoint {
.await?
{
let webpack_stats = generate_webpack_stats(
*module_graphs.base,
module_graphs.base.connect(),
app_entry.original_name.clone(),
client_assets.await?.into_iter().copied(),
)
Expand Down Expand Up @@ -1434,7 +1434,7 @@ impl AppEndpoint {
}
}

let actions = ServerActionsGraphs::new(*module_graphs.base, per_page_module_graph)
let actions = ServerActionsGraphs::new(module_graphs.base.connect(), per_page_module_graph)
.get_server_actions_for_endpoint(
*rsc_entry,
match runtime {
Expand All @@ -1453,7 +1453,7 @@ impl AppEndpoint {
NextRuntime::Edge => Vc::upcast(this.app_project.edge_rsc_module_context()),
NextRuntime::NodeJs => Vc::upcast(this.app_project.rsc_module_context()),
},
*module_graphs.full,
module_graphs.full.connect(),
this.app_project
.project()
.runtime_chunking_context(process_client_assets, runtime),
Expand All @@ -1471,7 +1471,7 @@ impl AppEndpoint {
*server_action_manifest_loader,
server_path.clone(),
process_client_assets,
*module_graphs.full,
module_graphs.full.connect(),
)
.to_resolved()
.await?;
Expand All @@ -1493,7 +1493,12 @@ impl AppEndpoint {
client_references_chunks,
client_chunking_context,
ssr_chunking_context,
async_module_info: module_graphs.full.async_module_info().to_resolved().await?,
async_module_info: module_graphs
.full
.connect()
.async_module_info()
.to_resolved()
.await?,
next_config: project.next_config().to_resolved().await?,
runtime,
mode: *project.next_mode().await?,
Expand Down Expand Up @@ -1566,7 +1571,7 @@ impl AppEndpoint {

if emit_manifests == EmitManifests::Full {
let dynamic_import_entries = collect_next_dynamic_chunks(
*module_graphs.full,
module_graphs.full.connect(),
*client_chunking_context,
next_dynamic_imports,
NextDynamicChunkAvailability::ClientReferences(
Expand Down Expand Up @@ -1682,7 +1687,7 @@ impl AppEndpoint {
let loadable_manifest_output = if emit_manifests == EmitManifests::Full {
// create react-loadable-manifest for next/dynamic
let dynamic_import_entries = collect_next_dynamic_chunks(
*module_graphs.full,
module_graphs.full.connect(),
*client_chunking_context,
next_dynamic_imports,
NextDynamicChunkAvailability::ClientReferences(
Expand Down
10 changes: 6 additions & 4 deletions crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
paths::{
all_server_paths, get_js_paths_from_root, get_wasm_paths_from_root, wasm_paths_to_bindings,
},
project::Project,
project::{Project, get_module_graph_operation},
route::{Endpoint, EndpointOutput, EndpointOutputPaths, ModuleGraphs},
};

Expand Down Expand Up @@ -249,8 +249,10 @@ impl Endpoint for InstrumentationEndpoint {
#[turbo_tasks::function]
async fn module_graphs(self: Vc<Self>) -> Result<Vc<ModuleGraphs>> {
let this = self.await?;
let module = self.entry_module();
let module_graph = this.project.module_graph(module).to_resolved().await?;
Ok(Vc::cell(vec![module_graph]))
let module = self.entry_module().to_resolved().await?;
Ok(Vc::cell(vec![get_module_graph_operation(
this.project,
module,
)]))
}
}
13 changes: 6 additions & 7 deletions crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
},
project::Project,
project::{Project, get_module_graph_operation},
route::{Endpoint, EndpointOutput, EndpointOutputPaths, ModuleGraphs},
};

Expand Down Expand Up @@ -390,11 +390,10 @@ impl Endpoint for MiddlewareEndpoint {
#[turbo_tasks::function]
async fn module_graphs(self: Vc<Self>) -> Result<Vc<ModuleGraphs>> {
let this = self.await?;
let module_graph = this
.project
.module_graph(self.entry_module())
.to_resolved()
.await?;
Ok(Vc::cell(vec![module_graph]))
let module = self.entry_module().to_resolved().await?;
Ok(Vc::cell(vec![get_module_graph_operation(
this.project,
module,
)]))
}
}
153 changes: 83 additions & 70 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use crate::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
},
project::Project,
project::{Project, get_module_graph_for_modules_operation},
route::{Endpoint, EndpointOutput, EndpointOutputPaths, ModuleGraphs, Route, Routes},
webpack_stats::generate_webpack_stats,
};
Expand Down Expand Up @@ -699,71 +699,13 @@ impl PageEndpoint {
}

#[turbo_tasks::function]
async fn client_module_graph(self: Vc<Self>) -> Result<Vc<ModuleGraph>> {
let this = self.await?;
let project = this.pages_project.project();
let evaluatable_assets = self.client_evaluatable_assets();
Ok(project.module_graph_for_modules(evaluatable_assets))
async fn client_module_graph(self: ResolvedVc<Self>) -> Result<Vc<ModuleGraph>> {
Ok(get_pages_client_module_graph_operation(self).connect())
}

#[turbo_tasks::function]
async fn ssr_module_graph(self: Vc<Self>) -> Result<Vc<ModuleGraph>> {
let this = self.await?;
let project = this.pages_project.project();

if *project.per_page_module_graph().await? {
let next_mode = project.next_mode();
let next_mode_ref = next_mode.await?;
let should_trace = next_mode_ref.is_production();
let should_read_binding_usage = next_mode_ref.is_production();

let ssr_chunk_module = self.internal_ssr_chunk_module().await?;
// Implements layout segment optimization to compute a graph "chain" for document, app,
// page
let mut graphs = vec![];
let mut visited_modules = VisitedModules::empty();
for module in [
ssr_chunk_module.document_module,
ssr_chunk_module.app_module,
]
.into_iter()
.flatten()
{
let graph = SingleModuleGraph::new_with_entries_visited_intern(
vec![ChunkGroupEntry::Shared(module)],
visited_modules,
should_trace,
should_read_binding_usage,
);
graphs.push(graph);
visited_modules = VisitedModules::concatenate(visited_modules, graph);
}

let graph = SingleModuleGraph::new_with_entries_visited_intern(
vec![ChunkGroupEntry::Entry(vec![ssr_chunk_module.ssr_module])],
visited_modules,
should_trace,
should_read_binding_usage,
);
graphs.push(graph);

let remove_unused_imports = *project
.next_config()
.turbopack_remove_unused_imports(next_mode)
.await?;

let graph = if remove_unused_imports {
let graph = ModuleGraph::from_graphs(graphs.clone());
let binding_usage_info = compute_binding_usage_info(graph, true);
ModuleGraph::from_graphs_without_unused_references(graphs, binding_usage_info)
} else {
ModuleGraph::from_graphs(graphs)
};

Ok(graph.connect())
} else {
Ok(*project.whole_app_module_graphs().await?.full)
}
async fn ssr_module_graph(self: ResolvedVc<Self>) -> Result<Vc<ModuleGraph>> {
Ok(get_pages_ssr_module_graph_operation(self).connect())
}

#[turbo_tasks::function]
Expand Down Expand Up @@ -1726,13 +1668,12 @@ impl Endpoint for PageEndpoint {

#[turbo_tasks::function]
async fn module_graphs(self: Vc<Self>) -> Result<Vc<ModuleGraphs>> {
let client_module_graph = self.client_module_graph().to_resolved().await?;
let ssr_module_graph = self.ssr_module_graph().to_resolved().await?;
Ok(Vc::cell(if client_module_graph != ssr_module_graph {
vec![client_module_graph, ssr_module_graph]
} else {
vec![ssr_module_graph]
}))
let this = self.to_resolved().await?;
let client_module_graph = get_pages_client_module_graph_operation(this);
let ssr_module_graph = get_pages_ssr_module_graph_operation(this);
// Note: We can't easily deduplicate these anymore since OperationVc
// doesn't implement Eq, but that's fine - they're operation references
Ok(Vc::cell(vec![client_module_graph, ssr_module_graph]))
}
}

Expand Down Expand Up @@ -1796,3 +1737,75 @@ pub enum SsrChunk {
regions: Option<Vec<RcStr>>,
},
}

#[turbo_tasks::function(operation)]
async fn get_pages_client_module_graph_operation(
endpoint: ResolvedVc<PageEndpoint>,
) -> Result<Vc<ModuleGraph>> {
let this = endpoint.await?;
let project = this.pages_project.project().to_resolved().await?;
let evaluatable_assets = endpoint.client_evaluatable_assets().to_resolved().await?;
Ok(get_module_graph_for_modules_operation(project, evaluatable_assets).connect())
}

#[turbo_tasks::function(operation)]
async fn get_pages_ssr_module_graph_operation(
endpoint: ResolvedVc<PageEndpoint>,
) -> Result<Vc<ModuleGraph>> {
let this = endpoint.await?;
let project = this.pages_project.project();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let project = this.pages_project.project();
let project = this.pages_project.project().to_resolved().await?;

Missing ResolvedVc conversion causes type mismatch when calling whole_app_module_graphs() method

Fix on Vercel


if *project.per_page_module_graph().await? {
let next_mode = project.next_mode();
let next_mode_ref = next_mode.await?;
let should_trace = next_mode_ref.is_production();
let should_read_binding_usage = next_mode_ref.is_production();

let ssr_chunk_module = endpoint.internal_ssr_chunk_module().await?;
// Implements layout segment optimization to compute a graph "chain" for document, app,
// page
let mut graphs = vec![];
let mut visited_modules = VisitedModules::empty();
for module in [
ssr_chunk_module.document_module,
ssr_chunk_module.app_module,
]
.into_iter()
.flatten()
{
let graph = SingleModuleGraph::new_with_entries_visited_intern(
vec![ChunkGroupEntry::Shared(module)],
visited_modules,
should_trace,
should_read_binding_usage,
);
graphs.push(graph);
visited_modules = VisitedModules::concatenate(visited_modules, graph);
}

let graph = SingleModuleGraph::new_with_entries_visited_intern(
vec![ChunkGroupEntry::Entry(vec![ssr_chunk_module.ssr_module])],
visited_modules,
should_trace,
should_read_binding_usage,
);
graphs.push(graph);

let remove_unused_imports = *project
.next_config()
.turbopack_remove_unused_imports(next_mode)
.await?;

let graph = if remove_unused_imports {
let graph = ModuleGraph::from_graphs(graphs.clone());
let binding_usage_info = compute_binding_usage_info(graph, true);
ModuleGraph::from_graphs_without_unused_references(graphs, binding_usage_info)
} else {
ModuleGraph::from_graphs(graphs)
};

Ok(graph.connect())
} else {
Ok(project.whole_app_module_graphs().await?.full.connect())
}
}
Loading
Loading