diff --git a/packages/next-swc/crates/next-api/src/app.rs b/packages/next-swc/crates/next-api/src/app.rs index e4b2ef1d7ba21..467b1aadf34df 100644 --- a/packages/next-swc/crates/next-api/src/app.rs +++ b/packages/next-swc/crates/next-api/src/app.rs @@ -586,10 +586,10 @@ impl AppEndpoint { .into_iter() .collect(), }; + let manifest_path_prefix = get_asset_prefix_from_pathname(&app_entry.pathname); let app_build_manifest_output = Vc::upcast(VirtualOutputAsset::new( node_root.join(format!( - "server/app{original_name}/app-build-manifest.json", - original_name = app_entry.original_name + "server/app{manifest_path_prefix}/page/app-build-manifest.json", )), AssetContent::file( File::from(serde_json::to_string_pretty(&app_build_manifest)?).into(), @@ -603,8 +603,7 @@ impl AppEndpoint { }; let build_manifest_output = Vc::upcast(VirtualOutputAsset::new( node_root.join(format!( - "server/app{original_name}/build-manifest.json", - original_name = app_entry.original_name + "server/app{manifest_path_prefix}/page/build-manifest.json", )), AssetContent::file(File::from(serde_json::to_string_pretty(&build_manifest)?).into()), )); @@ -623,11 +622,14 @@ impl AppEndpoint { fn create_app_paths_manifest( node_root: Vc, + pathname: &str, original_name: &str, filename: String, ) -> Result>> { - let path = - node_root.join(format!("server/app{original_name}/app-paths-manifest.json",)); + let manifest_path_prefix = get_asset_prefix_from_pathname(pathname); + let path = node_root.join(format!( + "server/app{manifest_path_prefix}/page/app-paths-manifest.json", + )); let app_paths_manifest = AppPathsManifest { node_server_app_paths: PagesManifest { pages: [(original_name.to_string(), filename)] @@ -727,7 +729,7 @@ impl AppEndpoint { 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{manifest_path_prefix}/middleware-manifest.json", + "server/app{manifest_path_prefix}/page/middleware-manifest.json", )), AssetContent::file( FileContent::Content(File::from(serde_json::to_string_pretty( @@ -739,8 +741,12 @@ impl AppEndpoint { server_assets.push(middleware_manifest_v2); // create app paths manifest - let app_paths_manifest_output = - create_app_paths_manifest(node_root, &app_entry.original_name, base_file)?; + let app_paths_manifest_output = create_app_paths_manifest( + node_root, + &app_entry.pathname, + &app_entry.original_name, + base_file, + )?; server_assets.push(app_paths_manifest_output); AppEndpointOutput::Edge { @@ -756,7 +762,7 @@ impl AppEndpoint { .rsc_chunking_context() .entry_chunk( server_path.join(format!( - "app/{original_name}.js", + "app{original_name}.js", original_name = app_entry.original_name )), app_entry.rsc_entry, @@ -766,6 +772,7 @@ impl AppEndpoint { let app_paths_manifest_output = create_app_paths_manifest( node_root, + &app_entry.pathname, &app_entry.original_name, server_path .await? diff --git a/packages/next-swc/crates/next-core/src/app_structure.rs b/packages/next-swc/crates/next-core/src/app_structure.rs index 2f849d87eca4f..f49278c52cb69 100644 --- a/packages/next-swc/crates/next-core/src/app_structure.rs +++ b/packages/next-swc/crates/next-core/src/app_structure.rs @@ -804,12 +804,12 @@ async fn directory_tree_to_entrypoints_internal( } else { format!("{path_prefix}/{subdir_name}") }, - if is_route_group || parallel_route_key.is_some() { - path_prefix.clone() - } else if path_prefix == "/" { + if parallel_route_key.is_some() { + original_name_prefix.clone() + } else if original_name_prefix == "/" { format!("/{subdir_name}") } else { - format!("{path_prefix}/{subdir_name}") + format!("{original_name_prefix}/{subdir_name}") }, ) .await?; diff --git a/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs b/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs index 078a8569d137c..4458410d02198 100644 --- a/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs +++ b/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs @@ -183,9 +183,9 @@ impl ClientReferenceManifest { AssetContent::file( File::from(formatdoc! { r#" - globalThis.__RSC_MANIFEST = globalThis.__RSC_MANIFEST || {{}}; - globalThis.__RSC_MANIFEST[{entry_name}] = {manifest} - "#, + globalThis.__RSC_MANIFEST = globalThis.__RSC_MANIFEST || {{}}; + globalThis.__RSC_MANIFEST[{entry_name}] = {manifest} + "#, entry_name = StringifyJs(&entry_name), manifest = StringifyJs(&client_reference_manifest_json) }) diff --git a/packages/next/src/server/lib/router-utils/setup-dev.ts b/packages/next/src/server/lib/router-utils/setup-dev.ts index 9f47e5caac0a6..a81d3e648ef5e 100644 --- a/packages/next/src/server/lib/router-utils/setup-dev.ts +++ b/packages/next/src/server/lib/router-utils/setup-dev.ts @@ -748,11 +748,9 @@ async function startWatcher(opts: SetupOpts) { break } case 'page-api': { - if (isApp) { - throw new Error( - `mis-matched route type: isApp && page for ${page}` - ) - } + // We don't throw on ensureOpts.isApp === true here + // since this can happen when app pages make + // api requests to page API routes. const writtenEndpoint = await processResult( page,