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: Single-graph-traversal and migrate next/dynamic #73222

Merged
merged 29 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2daccb9
wip
wbinnssmith Nov 26, 2024
a686531
Migrate next/dynamic to single-graph-traversal
mischnic Nov 26, 2024
d797285
Cleanup
mischnic Nov 26, 2024
0ccfa63
Cleanup
mischnic Nov 26, 2024
0b07a0d
Single graph traversal: collect app and page entries and construct a …
wbinnssmith Nov 27, 2024
744d7bd
Filter global graph for page for next/dynamic
mischnic Nov 27, 2024
72f0e2e
Unify SingleModuleGraph creation
mischnic Nov 27, 2024
12a3cb6
Store page entries for graph
mischnic Nov 27, 2024
603ff27
Rename variable
mischnic Nov 27, 2024
db88187
Cleanup, restrict public API, docs
mischnic Nov 27, 2024
8cb498d
Use new graph in pages router for next/dynamic
mischnic Nov 27, 2024
dd6bba9
Fix layer check
mischnic Nov 27, 2024
4f42f4e
Fix types
mischnic Nov 28, 2024
a50ff26
Fewer map conversions
mischnic Nov 28, 2024
e49244d
Provide graph.traverse_from_entry
mischnic Nov 28, 2024
0d8ded8
Instrumentation
mischnic Nov 28, 2024
ce06177
Try to prevent duplicate issues
mischnic Nov 28, 2024
821ff61
refactor get_module_graph_for_app_without_issues
mischnic Nov 29, 2024
a30dc4e
ignore sourcemaps
mischnic Nov 29, 2024
0e46216
ChunkingType::Isolated
mischnic Dec 3, 2024
ce92067
SingleModuleGraph::traverse_edges_from_entry
mischnic Dec 3, 2024
490f37c
Walk chunkable references instead
mischnic Dec 3, 2024
a0038dc
Take issues in SingleModuleGraph
mischnic Dec 3, 2024
468e410
Parallel traversal
mischnic Dec 4, 2024
fbf4845
SingleModuleGraphBuilderNode::Issues
mischnic Dec 4, 2024
f80a9e0
Add TracedDiGraph
mischnic Dec 4, 2024
b9937ba
Fixup ResolvedVc
mischnic Dec 9, 2024
284e4e4
Update crates/next-api/src/module_graph.rs
mischnic Dec 9, 2024
65d716f
Address review comments
mischnic Dec 10, 2024
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: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/next-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ workspace = true

[dependencies]
anyhow = { workspace = true, features = ["backtrace"] }
auto-hash-map = { workspace = true }
futures = { workspace = true }
indexmap = { workspace = true }
next-core = { workspace = true }
petgraph = { workspace = true, features = ["serde-1"]}
regex = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
76 changes: 21 additions & 55 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_rcstr::RcStr;
use turbo_tasks::{
fxindexmap, fxindexset, trace::TraceRawVcs, Completion, FxIndexMap, FxIndexSet, ResolvedVc,
TryJoinIterExt, Value, ValueToString, Vc,
fxindexmap, fxindexset, trace::TraceRawVcs, Completion, FxIndexSet, ResolvedVc, TryJoinIterExt,
Value, ValueToString, Vc,
};
use turbo_tasks_env::{CustomProcessEnv, ProcessEnv};
use turbo_tasks_fs::{File, FileContent, FileSystemPath};
Expand Down Expand Up @@ -69,12 +69,10 @@ use turbopack_core::{
use turbopack_ecmascript::resolve::cjs_resolve;

use crate::{
dynamic_imports::{
collect_chunk_group, collect_evaluated_chunk_group, collect_next_dynamic_imports,
VisitedDynamicImportModules,
},
dynamic_imports::{collect_chunk_group, collect_evaluated_chunk_group},
font::create_font_manifest,
loadable_manifest::create_react_loadable_manifest,
module_graph::get_reduced_graphs_for_endpoint,
nft_json::NftJsonAsset,
paths::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
Expand Down Expand Up @@ -912,7 +910,7 @@ impl AppEndpoint {
None
};

let (client_dynamic_imports, client_references, client_references_chunks) =
let (next_dynamic_imports, client_references, client_references_chunks) =
if process_client_components {
let client_shared_chunk_group = get_app_client_shared_chunk_group(
AssetIdent::from_path(this.app_project.project().project_path())
Expand All @@ -933,6 +931,15 @@ impl AppEndpoint {
}
let client_shared_availability_info = client_shared_chunk_group.availability_info;

let reduced_graphs = get_reduced_graphs_for_endpoint(
this.app_project.project(),
*rsc_entry,
Vc::upcast(this.app_project.client_module_context()),
);
let next_dynamic_imports = reduced_graphs
.get_next_dynamic_imports_for_endpoint(*rsc_entry)
.await?;

let client_references = {
let ServerEntries {
server_component_entries,
Expand Down Expand Up @@ -961,32 +968,6 @@ impl AppEndpoint {
};
let client_references_cell = client_references.clone().cell();

let client_dynamic_imports = {
let mut client_dynamic_imports = FxIndexMap::default();
let mut visited_modules = VisitedDynamicImportModules::empty();

for refs in client_references
.client_references_by_server_component
.values()
{
let result = collect_next_dynamic_imports(
refs.iter().map(|v| **v).collect(),
Vc::upcast(this.app_project.client_module_context()),
visited_modules,
)
.await?;
client_dynamic_imports.extend(
result
.client_dynamic_imports
.iter()
.map(|(k, v)| (*k, v.clone())),
);
visited_modules = *result.visited_modules;
}

client_dynamic_imports
};

let client_references_chunks = get_app_client_references_chunks(
client_references_cell,
client_chunking_context,
Expand Down Expand Up @@ -1130,7 +1111,7 @@ impl AppEndpoint {
}

(
Some(client_dynamic_imports),
Some(next_dynamic_imports),
Some(client_references_cell),
Some(client_references_chunks),
)
Expand Down Expand Up @@ -1310,19 +1291,11 @@ impl AppEndpoint {
.await?;
server_assets.insert(app_paths_manifest_output);

// create react-loadable-manifest for next/dynamic
let mut dynamic_import_modules = collect_next_dynamic_imports(
vec![*ResolvedVc::upcast(app_entry.rsc_entry)],
Vc::upcast(this.app_project.client_module_context()),
VisitedDynamicImportModules::empty(),
)
.await?
.client_dynamic_imports
.clone();
dynamic_import_modules.extend(client_dynamic_imports.into_iter().flatten());
let dynamic_import_entries = collect_evaluated_chunk_group(
Vc::upcast(client_chunking_context),
dynamic_import_modules,
next_dynamic_imports
.as_deref()
.unwrap_or(&Default::default()),
)
.await?;
let loadable_manifest_output = create_react_loadable_manifest(
Expand Down Expand Up @@ -1369,18 +1342,11 @@ impl AppEndpoint {

// create react-loadable-manifest for next/dynamic
let availability_info = Value::new(AvailabilityInfo::Root);
let mut dynamic_import_modules = collect_next_dynamic_imports(
vec![*ResolvedVc::upcast(app_entry.rsc_entry)],
Vc::upcast(this.app_project.client_module_context()),
VisitedDynamicImportModules::empty(),
)
.await?
.client_dynamic_imports
.clone();
dynamic_import_modules.extend(client_dynamic_imports.into_iter().flatten());
let dynamic_import_entries = collect_chunk_group(
Vc::upcast(client_chunking_context),
dynamic_import_modules,
next_dynamic_imports
.as_deref()
.unwrap_or(&Default::default()),
availability_info,
)
.await?;
Expand Down
Loading
Loading