Commit 5d532e0a authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by Niklas Mischkulnig

turbopack: use moduleLoading.prefix to deduplicate chunk path prefix in client-reference-manifest

Set moduleLoading.prefix to `{assetPrefix}/_next/static/chunks` so that
each entry in the chunks array only needs to store the filename (e.g.
`/foo.js`) rather than the full URL (e.g. `/_next/static/chunks/foo.js`),
matching the intent of the moduleLoading.prefix field and reducing manifest
size. Update the actions-tree-shaking test to reconstruct the full path via
moduleLoading.prefix before stripping the /_next/ prefix.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 5be8d2ee
...@@ -177,6 +177,8 @@ async fn build_manifest( ...@@ -177,6 +177,8 @@ async fn build_manifest(
rcstr!("") rcstr!("")
}; };
entry_manifest.module_loading.prefix =
format!("{}static/chunks", prefix_path).into();
entry_manifest.module_loading.cross_origin = next_config.cross_origin().owned().await?; entry_manifest.module_loading.cross_origin = next_config.cross_origin().owned().await?;
let ClientReferencesChunks { let ClientReferencesChunks {
client_component_client_chunks, client_component_client_chunks,
...@@ -282,10 +284,15 @@ async fn build_manifest( ...@@ -282,10 +284,15 @@ async fn build_manifest(
// be handled separately. // be handled separately.
.filter(|path| path.ends_with(".js")) .filter(|path| path.ends_with(".js"))
.map(|path| { .map(|path| {
// All client JS chunks are under `static/chunks/`. Strip
// that prefix here since `moduleLoading.prefix` already
// contains it, saving one repetition per entry.
let relative = path
.strip_prefix("static/chunks")
.unwrap_or(&path);
format!( format!(
"{}{}{}", "{}{}",
prefix_path, relative.split('/').map(encode_uri_component).format("/"),
path.split('/').map(encode_uri_component).format("/"),
suffix_path suffix_path
) )
}) })
......
...@@ -43,11 +43,13 @@ describe('app-dir - client-actions-tree-shaking', () => { ...@@ -43,11 +43,13 @@ describe('app-dir - client-actions-tree-shaking', () => {
chunks.add(chunk) chunks.add(chunk)
} }
} }
// clientModules is a mapping from module name to a set of URLs // clientModules is a mapping from module name to a set of chunk paths
// So strip that prefix and add it to the chunks // relative to moduleLoading.prefix. Reconstruct the full URL and strip
// the /_next/ prefix to get the path relative to the dist directory.
for (const clientModule of Object.values(clientManifest.clientModules)) { for (const clientModule of Object.values(clientManifest.clientModules)) {
for (const chunk of clientModule.chunks) { for (const chunk of clientModule.chunks) {
chunks.add(parseRelativeUrl(chunk).pathname.replace('/_next/', '')) const fullPath = clientManifest.moduleLoading.prefix + chunk
chunks.add(parseRelativeUrl(fullPath).pathname.replace('/_next/', ''))
} }
} }
} else { } else {
......
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