Skip to content

Commit 2af1e78

Browse files
jridgewellsokra
andauthored
turbopack: Chunking Refactor Step 2 (#56504)
### What? The second step in our chunking refactoring, this removes our use of Module::as_chunk and Module::as_root_chunk. Instead, the only way to generate a chunk is directly from a root ChunkItem. ### Why? In the end we want to avoid creating chunks from modules directly, but enforce everything going through the ChunkingContext to be chunked. This allows us to replace the existing chunking algorithm with a much more efficient one that avoid duplication between chunks in first place and doesn't require a post-chunking optimization. ### How? vercel/turborepo#6120 Re: #56467 Closes WEB-1721 Co-authored-by: Tobias Koppers <[email protected]>
1 parent 9d150b1 commit 2af1e78

File tree

14 files changed

+103
-145
lines changed

14 files changed

+103
-145
lines changed

Cargo.lock

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ swc_core = { version = "0.83.28", features = [
4040
testing = { version = "0.34.1" }
4141

4242
# Turbo crates
43-
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231005.2" }
43+
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231006.1" }
4444
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
45-
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231005.2" }
45+
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231006.1" }
4646
# [TODO]: need to refactor embed_directory! macro usage in next-core
47-
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231005.2" }
47+
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231006.1" }
4848

4949
# General Deps
5050

packages/next-swc/crates/next-api/src/app.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ use turbopack_binding::{
3939
turbopack::{
4040
core::{
4141
asset::{Asset, AssetContent},
42-
chunk::{ChunkableModuleExt, ChunkingContext, EvaluatableAssets},
42+
chunk::{ChunkingContext, EvaluatableAssets},
4343
file_source::FileSource,
44+
module::Module,
4445
output::{OutputAsset, OutputAssets},
4546
virtual_output::VirtualOutputAsset,
4647
},
@@ -507,7 +508,13 @@ impl AppEndpoint {
507508
let mut server_assets = vec![];
508509
let mut client_assets = vec![];
509510

511+
let app_entry = app_entry.await?;
512+
510513
let client_shared_chunks = get_app_client_shared_chunks(
514+
app_entry
515+
.rsc_entry
516+
.ident()
517+
.with_modifier(Vc::cell("client_shared_chunks".to_string())),
511518
this.app_project.client_runtime_entries(),
512519
this.app_project.project().client_chunking_context(),
513520
);
@@ -524,7 +531,6 @@ impl AppEndpoint {
524531
}
525532
}
526533

527-
let app_entry = app_entry.await?;
528534
let rsc_entry = app_entry.rsc_entry;
529535

530536
let rsc_entry_asset = Vc::upcast(rsc_entry);
@@ -707,9 +713,7 @@ impl AppEndpoint {
707713
}
708714

709715
let files = chunking_context.evaluated_chunk_group(
710-
app_entry
711-
.rsc_entry
712-
.as_root_chunk(Vc::upcast(chunking_context)),
716+
app_entry.rsc_entry.ident(),
713717
Vc::cell(evaluatable_assets),
714718
);
715719
server_assets.extend(files.await?.iter().copied());

packages/next-swc/crates/next-api/src/middleware.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use turbopack_binding::{
1313
turbopack::{
1414
core::{
1515
asset::AssetContent,
16-
chunk::{ChunkableModuleExt, ChunkingContext},
16+
chunk::ChunkingContext,
1717
context::AssetContext,
1818
module::Module,
1919
output::{OutputAsset, OutputAssets},
@@ -88,10 +88,8 @@ impl MiddlewareEndpoint {
8888

8989
let edge_chunking_context = self.project.edge_middleware_chunking_context();
9090

91-
let edge_files = edge_chunking_context.evaluated_chunk_group(
92-
module.as_root_chunk(Vc::upcast(edge_chunking_context)),
93-
Vc::cell(evaluatable_assets),
94-
);
91+
let edge_files = edge_chunking_context
92+
.evaluated_chunk_group(module.ident(), Vc::cell(evaluatable_assets));
9593

9694
Ok(edge_files)
9795
}

0 commit comments

Comments
 (0)