Skip to content

Commit 4e96512

Browse files
turbopack: keep chunk compositions stable across item edits
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
1 parent 2911ed4 commit 4e96512

9 files changed

Lines changed: 988 additions & 202 deletions

File tree

‎turbopack/crates/turbo-tasks-fs/src/cell_rope.rs‎

Lines changed: 284 additions & 46 deletions
Large diffs are not rendered by default.

‎turbopack/crates/turbo-tasks-fs/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use turbo_rcstr::RcStr;
5050
use turbo_tasks::{NonLocalValue, ResolvedVc, ValueToString, Vc, turbobail, turbofmt};
5151

5252
pub use crate::{
53-
cell_rope::{CellRope, CellRopeBuilder},
53+
cell_rope::{CellRope, CellRopeBuilder, CellRopePart},
5454
content::{
5555
File, FileContent, FileJsonContent, FileLine, FileLinesContent, FileMeta, LinkContent,
5656
LinkTarget, Permissions, PersistedFileContent, WriteLinkContent, WriteLinkTargetType,

‎turbopack/crates/turbopack-browser/src/ecmascript/content.rs‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use turbo_tasks_fs::FileContent;
88
use turbopack_core::{
99
asset::AssetContent,
1010
chunk::{ChunkingContext, ModuleId},
11-
code_builder::{Code, ComposedCode, ComposedCodeBuilder},
11+
code_builder::{Code, CodeComposition, CodeCompositionBuilder, ComposedCode},
1212
output::OutputAsset,
1313
source_map::{GenerateSourceMap, SourceMapAsset},
1414
version::{MergeableVersionedContent, Version, VersionedContent, VersionedContentMerger},
@@ -62,9 +62,27 @@ impl EcmascriptBrowserChunkContent {
6262
Ok(self.composed_code().await?.code())
6363
}
6464

65-
/// The chunk's code, composed from its chunk items' cells (see [`ComposedCode`]).
65+
/// The chunk's code, built from its [`composition`](Self::composition).
6666
#[turbo_tasks::function]
6767
async fn composed_code(self: Vc<Self>) -> Result<Vc<ComposedCode>> {
68+
let this = self.await?;
69+
let source_maps = *this
70+
.chunking_context
71+
.reference_chunk_source_maps(*ResolvedVc::upcast(this.chunk))
72+
.await?;
73+
let minification =
74+
ChunkMinification::for_chunking_context(Vc::upcast(*this.chunking_context)).await?;
75+
Ok(minification
76+
.finish_composition(self.composition().to_resolved().await?, source_maps)
77+
.await?
78+
.cell())
79+
}
80+
81+
/// The chunk's structure: its scaffolding, and references to its chunk items' cells (see
82+
/// [`CodeComposition`]). Doesn't read the chunk items' bytes, so it isn't recomputed (and its
83+
/// persisted body isn't rewritten) when only those change.
84+
#[turbo_tasks::function]
85+
async fn composition(self: Vc<Self>) -> Result<Vc<CodeComposition>> {
6886
let this = self.await?;
6987
let source_maps = *this
7088
.chunking_context
@@ -88,7 +106,7 @@ impl EcmascriptBrowserChunkContent {
88106
Either::Right(CURRENT_CHUNK_METHOD_DOCUMENT_CURRENT_SCRIPT_EXPR)
89107
}
90108
};
91-
let mut code = ComposedCodeBuilder::new(
109+
let mut code = CodeCompositionBuilder::new(
92110
source_maps,
93111
*this.chunking_context.debug_ids_enabled().await?,
94112
);
@@ -142,10 +160,7 @@ impl EcmascriptBrowserChunkContent {
142160
)?;
143161
code += "]);";
144162

145-
let (code, parts) = code.build();
146-
Ok(minification
147-
.finish_composed_chunk(code, parts, source_maps)?
148-
.cell())
163+
Ok(code.build().cell())
149164
}
150165

151166
#[turbo_tasks::function]

0 commit comments

Comments
 (0)