Skip to content

Commit c6f5089

Browse files
jridgewellsokra
andauthored
turbopack: Extract as_chunk into shared ChunkType trait (#56506)
### What? Step 3 in our chunking refactors extracts ChunkItem::as_chunk into a new ChunkType trait. This new trait isn't useful yet, but will eventually allow us to collect ChunkItems of a similar type into a lists, and perform chunking over all similar items at once. ### 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#6123 Re: #56504 Closes WEB-1724 Co-authored-by: Tobias Koppers <[email protected]>
1 parent bc15b58 commit c6f5089

File tree

7 files changed

+79
-77
lines changed

7 files changed

+79
-77
lines changed

Cargo.lock

Lines changed: 33 additions & 33 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-231006.2" }
43+
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231006.4" }
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-231006.2" }
45+
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231006.4" }
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-231006.2" }
47+
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231006.4" }
4848

4949
# General Deps
5050

packages/next-swc/crates/next-core/src/next_client_component/with_client_chunks.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use anyhow::{Context, Result};
22
use indoc::formatdoc;
3-
use turbo_tasks::{TryJoinIterExt, Value, ValueToString, Vc};
3+
use turbo_tasks::{TryJoinIterExt, ValueToString, Vc};
44
use turbopack_binding::{
55
turbo::tasks_fs::FileSystemPath,
66
turbopack::{
77
core::{
88
asset::{Asset, AssetContent},
99
chunk::{
10-
availability_info::AvailabilityInfo, Chunk, ChunkData, ChunkItem, ChunkItemExt,
11-
ChunkableModule, ChunkableModuleReference, ChunkingContext, ChunkingContextExt,
12-
ChunkingType, ChunkingTypeOption, ChunksData,
10+
ChunkData, ChunkItem, ChunkItemExt, ChunkType, ChunkableModule,
11+
ChunkableModuleReference, ChunkingContext, ChunkingContextExt, ChunkingType,
12+
ChunkingTypeOption, ChunksData,
1313
},
1414
ident::AssetIdent,
1515
module::Module,
@@ -18,11 +18,11 @@ use turbopack_binding::{
1818
reference::{ModuleReference, ModuleReferences, SingleOutputAssetReference},
1919
resolve::ModuleResolveResult,
2020
},
21-
ecmascript::chunk::EcmascriptChunkData,
21+
ecmascript::chunk::{EcmascriptChunkData, EcmascriptChunkType},
2222
turbopack::ecmascript::{
2323
chunk::{
24-
EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent,
25-
EcmascriptChunkPlaceable, EcmascriptChunkingContext, EcmascriptExports,
24+
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
25+
EcmascriptChunkingContext, EcmascriptExports,
2626
},
2727
utils::StringifyJs,
2828
},
@@ -239,12 +239,13 @@ impl ChunkItem for WithClientChunksChunkItem {
239239
}
240240

241241
#[turbo_tasks::function]
242-
fn as_chunk(&self, availability_info: Value<AvailabilityInfo>) -> Vc<Box<dyn Chunk>> {
243-
Vc::upcast(EcmascriptChunk::new(
244-
Vc::upcast(self.context.with_layer("rsc".to_string())),
245-
Vc::upcast(self.inner),
246-
availability_info,
247-
))
242+
fn ty(&self) -> Vc<Box<dyn ChunkType>> {
243+
Vc::upcast(Vc::<EcmascriptChunkType>::default())
244+
}
245+
246+
#[turbo_tasks::function]
247+
fn module(&self) -> Vc<Box<dyn Module>> {
248+
Vc::upcast(self.inner)
248249
}
249250
}
250251

0 commit comments

Comments
 (0)