diff --git a/packages/next-swc/crates/next-api/src/app.rs b/packages/next-swc/crates/next-api/src/app.rs index dc6781d021fa4..e4b2ef1d7ba21 100644 --- a/packages/next-swc/crates/next-api/src/app.rs +++ b/packages/next-swc/crates/next-api/src/app.rs @@ -27,7 +27,7 @@ use next_core::{ get_server_module_options_context, get_server_resolve_options_context, get_server_runtime_entries, ServerContextType, }, - util::NextRuntime, + util::{get_asset_prefix_from_pathname, NextRuntime}, }; use serde::{Deserialize, Serialize}; use turbo_tasks::{trace::TraceRawVcs, Completion, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc}; @@ -706,7 +706,7 @@ impl AppEndpoint { }; let edge_function_definition = EdgeFunctionDefinition { files: files_paths_from_root, - name: app_entry.original_name.to_string(), + name: app_entry.pathname.to_string(), page: app_entry.original_name.clone(), regions: app_entry .config @@ -718,16 +718,16 @@ impl AppEndpoint { ..Default::default() }; let middleware_manifest_v2 = MiddlewaresManifestV2 { - sorted_middleware: vec![app_entry.original_name.clone()], + sorted_middleware: vec![app_entry.pathname.clone()], middleware: Default::default(), - functions: [(app_entry.original_name.clone(), edge_function_definition)] + functions: [(app_entry.pathname.clone(), edge_function_definition)] .into_iter() .collect(), }; + let manifest_path_prefix = get_asset_prefix_from_pathname(&app_entry.pathname); let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new( node_root.join(format!( - "server/app{original_name}/middleware-manifest.json", - original_name = app_entry.original_name + "server/app{manifest_path_prefix}/middleware-manifest.json", )), AssetContent::file( FileContent::Content(File::from(serde_json::to_string_pretty( diff --git a/packages/next-swc/crates/next-api/src/pages.rs b/packages/next-swc/crates/next-api/src/pages.rs index 54c0d5a21fe1c..cebb932770913 100644 --- a/packages/next-swc/crates/next-api/src/pages.rs +++ b/packages/next-swc/crates/next-api/src/pages.rs @@ -849,22 +849,23 @@ impl PageEndpoint { let original_name = this.original_name.await?; let edge_function_definition = EdgeFunctionDefinition { files: files_paths_from_root, - name: original_name.to_string(), + name: pathname.to_string(), page: original_name.to_string(), regions: None, matchers: vec![matchers], ..Default::default() }; let middleware_manifest_v2 = MiddlewaresManifestV2 { - sorted_middleware: vec![original_name.to_string()], + sorted_middleware: vec![pathname.to_string()], middleware: Default::default(), - functions: [(original_name.to_string(), edge_function_definition)] + functions: [(pathname.to_string(), edge_function_definition)] .into_iter() .collect(), }; + let manifest_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?); let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new( node_root.join(format!( - "server/pages{original_name}/middleware-manifest.json" + "server/pages{manifest_path_prefix}/middleware-manifest.json" )), AssetContent::file( FileContent::Content(File::from(serde_json::to_string_pretty( diff --git a/packages/next-swc/crates/next-core/src/next_app/app_route_entry.rs b/packages/next-swc/crates/next-core/src/next_app/app_route_entry.rs index d6d80050e61ef..8cc80bd78926e 100644 --- a/packages/next-swc/crates/next-core/src/next_app/app_route_entry.rs +++ b/packages/next-swc/crates/next-core/src/next_app/app_route_entry.rs @@ -143,7 +143,7 @@ pub async fn wrap_edge_entry( context: Vc, project_root: Vc, entry: Vc>, - original_name: String, + pathname: String, ) -> Result>> { let mut source = RopeBuilder::default(); writedoc!( @@ -158,7 +158,7 @@ pub async fn wrap_edge_entry( default: EdgeRouteModuleWrapper.wrap(module.routeModule), }} "#, - StringifyJs(&format_args!("middleware_{}", original_name)) + StringifyJs(&format_args!("middleware_{}", pathname)) )?; let file = File::from(source.build()); // TODO(alexkirsz) Figure out how to name this virtual asset. diff --git a/packages/next-swc/crates/next-core/src/next_pages/page_entry.rs b/packages/next-swc/crates/next-core/src/next_pages/page_entry.rs index 8c01293a2640e..94629f4332020 100644 --- a/packages/next-swc/crates/next-core/src/next_pages/page_entry.rs +++ b/packages/next-swc/crates/next-core/src/next_pages/page_entry.rs @@ -125,7 +125,7 @@ pub async fn create_page_ssr_entry_module( ssr_module_context, project_root, ssr_module, - definition_page.to_string(), + definition_pathname.to_string(), ); } @@ -143,7 +143,7 @@ pub async fn wrap_edge_entry( context: Vc>, project_root: Vc, entry: Vc>, - original_name: String, + pathname: String, ) -> Result>> { let mut source = RopeBuilder::default(); writedoc!( @@ -154,7 +154,7 @@ pub async fn wrap_edge_entry( self._ENTRIES ||= {{}} self._ENTRIES[{}] = module "#, - StringifyJs(&format_args!("middleware_{}", original_name)) + StringifyJs(&format_args!("middleware_{}", pathname)) )?; let file = File::from(source.build()); // TODO(alexkirsz) Figure out how to name this virtual asset.