Unverified Commit 664110c1 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: read asset entries strongly consistent (#77974)

### What?

Avoid eventual consistent results influencing the map state.
parent 741f6fc9
...@@ -120,22 +120,11 @@ impl VersionedContentMap { ...@@ -120,22 +120,11 @@ impl VersionedContentMap {
client_relative_path: Vc<FileSystemPath>, client_relative_path: Vc<FileSystemPath>,
client_output_path: Vc<FileSystemPath>, client_output_path: Vc<FileSystemPath>,
) -> Result<Vc<OptionMapEntry>> { ) -> Result<Vc<OptionMapEntry>> {
let assets = assets_operation.connect(); let entries = get_entries(assets_operation)
async fn get_entries( .read_strongly_consistent()
assets: Vc<OutputAssets>, .await
) -> Result<Vec<(ResolvedVc<FileSystemPath>, ResolvedVc<Box<dyn OutputAsset>>)>> { // Any error should result in an empty list, which removes all assets from the map
let assets_ref = assets.await?; .ok();
let entries = assets_ref
.iter()
.map(|&asset| async move {
let path = asset.path().to_resolved().await?;
Ok((path, asset))
})
.try_join()
.await?;
Ok(entries)
}
let entries = get_entries(assets).await.unwrap_or_default();
self.map_path_to_op.update_conditionally(|map| { self.map_path_to_op.update_conditionally(|map| {
let mut changed = false; let mut changed = false;
...@@ -143,7 +132,7 @@ impl VersionedContentMap { ...@@ -143,7 +132,7 @@ impl VersionedContentMap {
// get current map's keys, subtract keys that don't exist in operation // get current map's keys, subtract keys that don't exist in operation
let mut stale_assets = map.0.keys().copied().collect::<FxHashSet<_>>(); let mut stale_assets = map.0.keys().copied().collect::<FxHashSet<_>>();
for (k, _) in entries.iter() { for (k, _) in entries.iter().flatten() {
let res = map.0.entry(*k).or_default().insert(assets_operation); let res = map.0.entry(*k).or_default().insert(assets_operation);
stale_assets.remove(k); stale_assets.remove(k);
changed = changed || res; changed = changed || res;
...@@ -163,12 +152,17 @@ impl VersionedContentMap { ...@@ -163,12 +152,17 @@ impl VersionedContentMap {
}); });
// Make sure all written client assets are up-to-date // Make sure all written client assets are up-to-date
let _ = emit_assets(assets, node_root, client_relative_path, client_output_path) let _ = emit_assets(
.resolve() assets_operation.connect(),
.await?; node_root,
client_relative_path,
client_output_path,
)
.resolve()
.await?;
let map_entry = Vc::cell(Some(MapEntry { let map_entry = Vc::cell(Some(MapEntry {
assets_operation, assets_operation,
path_to_asset: entries.into_iter().collect(), path_to_asset: entries.iter().flatten().copied().collect(),
})); }));
Ok(map_entry) Ok(map_entry)
} }
...@@ -265,6 +259,25 @@ impl VersionedContentMap { ...@@ -265,6 +259,25 @@ impl VersionedContentMap {
} }
} }
type GetEntriesResultT = Vec<(ResolvedVc<FileSystemPath>, ResolvedVc<Box<dyn OutputAsset>>)>;
#[turbo_tasks::value(transparent)]
struct GetEntriesResult(GetEntriesResultT);
#[turbo_tasks::function(operation)]
async fn get_entries(assets: OperationVc<OutputAssets>) -> Result<Vc<GetEntriesResult>> {
let assets_ref = assets.connect().await?;
let entries = assets_ref
.iter()
.map(|&asset| async move {
let path = asset.path().to_resolved().await?;
Ok((path, asset))
})
.try_join()
.await?;
Ok(Vc::cell(entries))
}
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation)]
fn compute_entry_operation( fn compute_entry_operation(
map: ResolvedVc<VersionedContentMap>, map: ResolvedVc<VersionedContentMap>,
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
} from 'next-test-utils' } from 'next-test-utils'
describe('app-dir - missing required html tags', () => { describe('app-dir - missing required html tags', () => {
const { next, isTurbopack } = nextTestSetup({ files: __dirname }) const { next } = nextTestSetup({ files: __dirname })
it('should display correct error count in dev indicator', async () => { it('should display correct error count in dev indicator', async () => {
const browser = await next.browser('/') const browser = await next.browser('/')
...@@ -75,22 +75,7 @@ describe('app-dir - missing required html tags', () => { ...@@ -75,22 +75,7 @@ describe('app-dir - missing required html tags', () => {
) )
) )
if (isTurbopack) { // TODO(NDX-768): Should show "missing tags" error
await assertHasRedbox(browser) await assertNoRedbox(browser)
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Missing <html> and <body> tags in the root layout.
Read more at https://nextjs.org/docs/messages/missing-root-layout-tags",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
} else {
// TODO(NDX-768): Should show "missing tags" error
await assertNoRedbox(browser)
}
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment