Skip to content

Commit

Permalink
Turbopack: dedupe middleware-manifest entries (#76621)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored Feb 28, 2025
1 parent be22841 commit fceb1d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ impl AppEndpoint {
let mut server_assets = fxindexset![];
let mut client_assets = fxindexset![];
// assets to add to the middleware manifest (to be loaded in the edge runtime).
let mut middleware_assets = vec![];
let mut middleware_assets = fxindexset![];

let runtime = app_entry.config.await?.runtime.unwrap_or_default();

Expand Down Expand Up @@ -1314,7 +1314,6 @@ impl AppEndpoint {
.values()
{
let ssr_chunks = ssr_chunks.await?;

middleware_assets.extend(ssr_chunks);
}
}
Expand Down Expand Up @@ -1387,7 +1386,7 @@ impl AppEndpoint {
.await?;
server_assets.insert(entry_manifest);
if runtime == NextRuntime::Edge {
middleware_assets.push(entry_manifest);
middleware_assets.insert(entry_manifest);
}
client_reference_manifest = Some(entry_manifest);

Expand All @@ -1411,13 +1410,13 @@ impl AppEndpoint {
// global variables defined in these files
//
// they are created in `setup-dev-bundler.ts`
let mut file_paths_from_root = vec![
let mut file_paths_from_root = fxindexset![
"server/server-reference-manifest.js".into(),
"server/middleware-build-manifest.js".into(),
"server/next-font-manifest.js".into(),
"server/interception-route-rewrite-manifest.js".into(),
];
let mut wasm_paths_from_root = vec![];
let mut wasm_paths_from_root = fxindexset![];

let node_root_value = node_root.await?;

Expand Down Expand Up @@ -1476,8 +1475,8 @@ impl AppEndpoint {
..Default::default()
};
let edge_function_definition = EdgeFunctionDefinition {
files: file_paths_from_root,
wasm: wasm_paths_to_bindings(wasm_paths_from_root),
files: file_paths_from_root.into_iter().collect(),
wasm: wasm_paths_to_bindings(wasm_paths_from_root.into_iter().collect()),
assets: paths_to_bindings(all_assets),
name: app_entry.pathname.clone(),
page: app_entry.original_name.clone(),
Expand Down
12 changes: 6 additions & 6 deletions crates/next-api/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ pub async fn all_paths_in_root(

pub(crate) async fn get_paths_from_root(
root: &FileSystemPath,
output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
output_assets: impl IntoIterator<Item = &ResolvedVc<Box<dyn OutputAsset>>>,
filter: impl FnOnce(&str) -> bool + Copy,
) -> Result<Vec<RcStr>> {
output_assets
.iter()
.into_iter()
.map(move |&file| async move {
let path = &*file.path().await?;
let Some(relative) = root.get_path_to(path) else {
Expand All @@ -101,21 +101,21 @@ pub(crate) async fn get_paths_from_root(

pub(crate) async fn get_js_paths_from_root(
root: &FileSystemPath,
output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
output_assets: impl IntoIterator<Item = &ResolvedVc<Box<dyn OutputAsset>>>,
) -> Result<Vec<RcStr>> {
get_paths_from_root(root, output_assets, |path| path.ends_with(".js")).await
}

pub(crate) async fn get_wasm_paths_from_root(
root: &FileSystemPath,
output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
output_assets: impl IntoIterator<Item = &ResolvedVc<Box<dyn OutputAsset>>>,
) -> Result<Vec<RcStr>> {
get_paths_from_root(root, output_assets, |path| path.ends_with(".wasm")).await
}

pub(crate) async fn get_asset_paths_from_root(
root: &FileSystemPath,
output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
output_assets: impl IntoIterator<Item = &ResolvedVc<Box<dyn OutputAsset>>>,
) -> Result<Vec<RcStr>> {
get_paths_from_root(root, output_assets, |path| {
!path.ends_with(".js") && !path.ends_with(".map") && !path.ends_with(".wasm")
Expand All @@ -125,7 +125,7 @@ pub(crate) async fn get_asset_paths_from_root(

pub(crate) async fn get_font_paths_from_root(
root: &FileSystemPath,
output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
output_assets: impl IntoIterator<Item = &ResolvedVc<Box<dyn OutputAsset>>>,
) -> Result<Vec<RcStr>> {
get_paths_from_root(root, output_assets, |path| {
path.ends_with(".woff")
Expand Down

0 comments on commit fceb1d1

Please sign in to comment.