Skip to content

Commit 664110c

Browse files
authored
Turbopack: read asset entries strongly consistent (#77974)
### What? Avoid eventual consistent results influencing the map state.
1 parent 741f6fc commit 664110c

File tree

2 files changed

+37
-39
lines changed

2 files changed

+37
-39
lines changed

crates/next-api/src/versioned_content_map.rs

+34-21
Original file line numberDiff line numberDiff line change
@@ -120,30 +120,19 @@ impl VersionedContentMap {
120120
client_relative_path: Vc<FileSystemPath>,
121121
client_output_path: Vc<FileSystemPath>,
122122
) -> Result<Vc<OptionMapEntry>> {
123-
let assets = assets_operation.connect();
124-
async fn get_entries(
125-
assets: Vc<OutputAssets>,
126-
) -> Result<Vec<(ResolvedVc<FileSystemPath>, ResolvedVc<Box<dyn OutputAsset>>)>> {
127-
let assets_ref = assets.await?;
128-
let entries = assets_ref
129-
.iter()
130-
.map(|&asset| async move {
131-
let path = asset.path().to_resolved().await?;
132-
Ok((path, asset))
133-
})
134-
.try_join()
135-
.await?;
136-
Ok(entries)
137-
}
138-
let entries = get_entries(assets).await.unwrap_or_default();
123+
let entries = get_entries(assets_operation)
124+
.read_strongly_consistent()
125+
.await
126+
// Any error should result in an empty list, which removes all assets from the map
127+
.ok();
139128

140129
self.map_path_to_op.update_conditionally(|map| {
141130
let mut changed = false;
142131

143132
// get current map's keys, subtract keys that don't exist in operation
144133
let mut stale_assets = map.0.keys().copied().collect::<FxHashSet<_>>();
145134

146-
for (k, _) in entries.iter() {
135+
for (k, _) in entries.iter().flatten() {
147136
let res = map.0.entry(*k).or_default().insert(assets_operation);
148137
stale_assets.remove(k);
149138
changed = changed || res;
@@ -163,12 +152,17 @@ impl VersionedContentMap {
163152
});
164153

165154
// Make sure all written client assets are up-to-date
166-
let _ = emit_assets(assets, node_root, client_relative_path, client_output_path)
167-
.resolve()
168-
.await?;
155+
let _ = emit_assets(
156+
assets_operation.connect(),
157+
node_root,
158+
client_relative_path,
159+
client_output_path,
160+
)
161+
.resolve()
162+
.await?;
169163
let map_entry = Vc::cell(Some(MapEntry {
170164
assets_operation,
171-
path_to_asset: entries.into_iter().collect(),
165+
path_to_asset: entries.iter().flatten().copied().collect(),
172166
}));
173167
Ok(map_entry)
174168
}
@@ -265,6 +259,25 @@ impl VersionedContentMap {
265259
}
266260
}
267261

262+
type GetEntriesResultT = Vec<(ResolvedVc<FileSystemPath>, ResolvedVc<Box<dyn OutputAsset>>)>;
263+
264+
#[turbo_tasks::value(transparent)]
265+
struct GetEntriesResult(GetEntriesResultT);
266+
267+
#[turbo_tasks::function(operation)]
268+
async fn get_entries(assets: OperationVc<OutputAssets>) -> Result<Vc<GetEntriesResult>> {
269+
let assets_ref = assets.connect().await?;
270+
let entries = assets_ref
271+
.iter()
272+
.map(|&asset| async move {
273+
let path = asset.path().to_resolved().await?;
274+
Ok((path, asset))
275+
})
276+
.try_join()
277+
.await?;
278+
Ok(Vc::cell(entries))
279+
}
280+
268281
#[turbo_tasks::function(operation)]
269282
fn compute_entry_operation(
270283
map: ResolvedVc<VersionedContentMap>,

test/development/app-dir/missing-required-html-tags/index.test.ts

+3-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'next-test-utils'
99

1010
describe('app-dir - missing required html tags', () => {
11-
const { next, isTurbopack } = nextTestSetup({ files: __dirname })
11+
const { next } = nextTestSetup({ files: __dirname })
1212

1313
it('should display correct error count in dev indicator', async () => {
1414
const browser = await next.browser('/')
@@ -75,22 +75,7 @@ describe('app-dir - missing required html tags', () => {
7575
)
7676
)
7777

78-
if (isTurbopack) {
79-
await assertHasRedbox(browser)
80-
await expect(browser).toDisplayRedbox(`
81-
{
82-
"count": 1,
83-
"description": "Error: Missing <html> and <body> tags in the root layout.
84-
Read more at https://nextjs.org/docs/messages/missing-root-layout-tags",
85-
"environmentLabel": null,
86-
"label": "Runtime Error",
87-
"source": null,
88-
"stack": [],
89-
}
90-
`)
91-
} else {
92-
// TODO(NDX-768): Should show "missing tags" error
93-
await assertNoRedbox(browser)
94-
}
78+
// TODO(NDX-768): Should show "missing tags" error
79+
await assertNoRedbox(browser)
9580
})
9681
})

0 commit comments

Comments
 (0)