Unverified Commit 202db657 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: don't emit polyfill chunk for API routes (#91331)

1. This is misldeading in the bundle analyzer view
2. If you have a Nextjs app consisting of only API routes, then there is
no need to ever write out any polyfill chunk.
parent e22988e5
...@@ -1358,6 +1358,9 @@ impl AppEndpoint { ...@@ -1358,6 +1358,9 @@ impl AppEndpoint {
let manifest_path_prefix = &app_entry.original_name; let manifest_path_prefix = &app_entry.original_name;
// Only Pages need a polyfill chunk, Routes handlers don't have any inherent code that runs
// in the browser.
let polyfill_output_asset = if matches!(this.ty, AppEndpointType::Page { .. }) {
// polyfill-nomodule.js is a pre-compiled asset distributed as part of next // polyfill-nomodule.js is a pre-compiled asset distributed as part of next
let next_package = get_next_package(project.project_path().owned().await?).await?; let next_package = get_next_package(project.project_path().owned().await?).await?;
let polyfill_source_path = let polyfill_source_path =
...@@ -1397,6 +1400,10 @@ impl AppEndpoint { ...@@ -1397,6 +1400,10 @@ impl AppEndpoint {
.await?; .await?;
client_assets.insert(ResolvedVc::upcast(polyfill_source_map_asset)); client_assets.insert(ResolvedVc::upcast(polyfill_source_map_asset));
} }
Some(polyfill_output_asset)
} else {
None
};
let client_assets: ResolvedVc<OutputAssets> = let client_assets: ResolvedVc<OutputAssets> =
ResolvedVc::cell(client_assets.into_iter().collect::<Vec<_>>()); ResolvedVc::cell(client_assets.into_iter().collect::<Vec<_>>());
...@@ -1437,7 +1444,7 @@ impl AppEndpoint { ...@@ -1437,7 +1444,7 @@ impl AppEndpoint {
client_relative_path: client_relative_path.clone(), client_relative_path: client_relative_path.clone(),
pages: Default::default(), pages: Default::default(),
root_main_files: client_shared_chunks, root_main_files: client_shared_chunks,
polyfill_files: vec![polyfill_output_asset], polyfill_files: polyfill_output_asset.into_iter().collect(),
}; };
server_assets.insert(ResolvedVc::upcast(build_manifest.resolved_cell())); server_assets.insert(ResolvedVc::upcast(build_manifest.resolved_cell()));
} }
......
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