Skip to content

Commit 16ed89e

Browse files
authored
[Turbopack] improve hmr stability (#69985)
### What? Use strongly consistent reads to improve hmr stability
1 parent 114667d commit 16ed89e

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

crates/next-api/src/project.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,12 @@ impl Project {
12011201
// INVALIDATION: This is intentionally untracked to avoid invalidating this
12021202
// function completely. We want to initialize the VersionState with the
12031203
// first seen version of the session.
1204-
VersionState::new(version.into_trait_ref_untracked().await?).await
1204+
VersionState::new(
1205+
version
1206+
.into_trait_ref_strongly_consistent_untracked()
1207+
.await?,
1208+
)
1209+
.await
12051210
}
12061211

12071212
/// Emits opaque HMR events whenever a change is detected in the chunk group

crates/next-api/src/versioned_content_map.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,25 @@ impl VersionedContentMap {
9595
client_output_path: Vc<FileSystemPath>,
9696
) -> Result<Vc<OptionMapEntry>> {
9797
let assets = *assets_operation.await?;
98-
let entries: Vec<_> = assets
99-
.await?
100-
.iter()
101-
.map(|&asset| async move { Ok((asset.ident().path().resolve().await?, asset, assets)) })
102-
.try_join()
103-
.await?;
104-
98+
async fn get_entries(
99+
assets: Vc<OutputAssets>,
100+
) -> Result<Vec<(Vc<FileSystemPath>, Vc<Box<dyn OutputAsset>>)>> {
101+
let assets_ref = assets.await?;
102+
let entries = assets_ref
103+
.iter()
104+
.map(|&asset| async move {
105+
let path = asset.ident().path().resolve().await?;
106+
Ok((path, asset))
107+
})
108+
.try_join()
109+
.await?;
110+
Ok(entries)
111+
}
112+
let entries = get_entries(assets).await.unwrap_or_default();
105113
self.await?.map_path_to_op.update_conditionally(|map| {
106114
let mut changed = false;
107-
for &(k, _, v) in entries.iter() {
108-
if map.insert(k, v) != Some(v) {
115+
for &(k, _) in entries.iter() {
116+
if map.insert(k, assets) != Some(assets) {
109117
changed = true;
110118
}
111119
}
@@ -116,7 +124,7 @@ impl VersionedContentMap {
116124
let map_entry = Vc::cell(Some(MapEntry {
117125
assets_operation: assets,
118126
side_effects,
119-
path_to_asset: entries.into_iter().map(|(k, v, _)| (k, v)).collect(),
127+
path_to_asset: entries.into_iter().collect(),
120128
}));
121129
Ok(map_entry)
122130
}

0 commit comments

Comments
 (0)