Unverified Commit ef0c5e20 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

add support for app pages to next.rs api (#54668)

### What?

fix the paths for app pages with route groups (e. g. `(dashboard)`)


Closes WEB-1463

---------
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 1491d4c2
...@@ -586,10 +586,10 @@ impl AppEndpoint { ...@@ -586,10 +586,10 @@ impl AppEndpoint {
.into_iter() .into_iter()
.collect(), .collect(),
}; };
let manifest_path_prefix = get_asset_prefix_from_pathname(&app_entry.pathname);
let app_build_manifest_output = Vc::upcast(VirtualOutputAsset::new( let app_build_manifest_output = Vc::upcast(VirtualOutputAsset::new(
node_root.join(format!( node_root.join(format!(
"server/app{original_name}/app-build-manifest.json", "server/app{manifest_path_prefix}/page/app-build-manifest.json",
original_name = app_entry.original_name
)), )),
AssetContent::file( AssetContent::file(
File::from(serde_json::to_string_pretty(&app_build_manifest)?).into(), File::from(serde_json::to_string_pretty(&app_build_manifest)?).into(),
...@@ -603,8 +603,7 @@ impl AppEndpoint { ...@@ -603,8 +603,7 @@ impl AppEndpoint {
}; };
let build_manifest_output = Vc::upcast(VirtualOutputAsset::new( let build_manifest_output = Vc::upcast(VirtualOutputAsset::new(
node_root.join(format!( node_root.join(format!(
"server/app{original_name}/build-manifest.json", "server/app{manifest_path_prefix}/page/build-manifest.json",
original_name = app_entry.original_name
)), )),
AssetContent::file(File::from(serde_json::to_string_pretty(&build_manifest)?).into()), AssetContent::file(File::from(serde_json::to_string_pretty(&build_manifest)?).into()),
)); ));
...@@ -623,11 +622,14 @@ impl AppEndpoint { ...@@ -623,11 +622,14 @@ impl AppEndpoint {
fn create_app_paths_manifest( fn create_app_paths_manifest(
node_root: Vc<FileSystemPath>, node_root: Vc<FileSystemPath>,
pathname: &str,
original_name: &str, original_name: &str,
filename: String, filename: String,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<Vc<Box<dyn OutputAsset>>> {
let path = let manifest_path_prefix = get_asset_prefix_from_pathname(pathname);
node_root.join(format!("server/app{original_name}/app-paths-manifest.json",)); let path = node_root.join(format!(
"server/app{manifest_path_prefix}/page/app-paths-manifest.json",
));
let app_paths_manifest = AppPathsManifest { let app_paths_manifest = AppPathsManifest {
node_server_app_paths: PagesManifest { node_server_app_paths: PagesManifest {
pages: [(original_name.to_string(), filename)] pages: [(original_name.to_string(), filename)]
...@@ -727,7 +729,7 @@ impl AppEndpoint { ...@@ -727,7 +729,7 @@ impl AppEndpoint {
let manifest_path_prefix = get_asset_prefix_from_pathname(&app_entry.pathname); let manifest_path_prefix = get_asset_prefix_from_pathname(&app_entry.pathname);
let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new( let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new(
node_root.join(format!( node_root.join(format!(
"server/app{manifest_path_prefix}/middleware-manifest.json", "server/app{manifest_path_prefix}/page/middleware-manifest.json",
)), )),
AssetContent::file( AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty( FileContent::Content(File::from(serde_json::to_string_pretty(
...@@ -739,8 +741,12 @@ impl AppEndpoint { ...@@ -739,8 +741,12 @@ impl AppEndpoint {
server_assets.push(middleware_manifest_v2); server_assets.push(middleware_manifest_v2);
// create app paths manifest // create app paths manifest
let app_paths_manifest_output = let app_paths_manifest_output = create_app_paths_manifest(
create_app_paths_manifest(node_root, &app_entry.original_name, base_file)?; node_root,
&app_entry.pathname,
&app_entry.original_name,
base_file,
)?;
server_assets.push(app_paths_manifest_output); server_assets.push(app_paths_manifest_output);
AppEndpointOutput::Edge { AppEndpointOutput::Edge {
...@@ -756,7 +762,7 @@ impl AppEndpoint { ...@@ -756,7 +762,7 @@ impl AppEndpoint {
.rsc_chunking_context() .rsc_chunking_context()
.entry_chunk( .entry_chunk(
server_path.join(format!( server_path.join(format!(
"app/{original_name}.js", "app{original_name}.js",
original_name = app_entry.original_name original_name = app_entry.original_name
)), )),
app_entry.rsc_entry, app_entry.rsc_entry,
...@@ -766,6 +772,7 @@ impl AppEndpoint { ...@@ -766,6 +772,7 @@ impl AppEndpoint {
let app_paths_manifest_output = create_app_paths_manifest( let app_paths_manifest_output = create_app_paths_manifest(
node_root, node_root,
&app_entry.pathname,
&app_entry.original_name, &app_entry.original_name,
server_path server_path
.await? .await?
......
...@@ -804,12 +804,12 @@ async fn directory_tree_to_entrypoints_internal( ...@@ -804,12 +804,12 @@ async fn directory_tree_to_entrypoints_internal(
} else { } else {
format!("{path_prefix}/{subdir_name}") format!("{path_prefix}/{subdir_name}")
}, },
if is_route_group || parallel_route_key.is_some() { if parallel_route_key.is_some() {
path_prefix.clone() original_name_prefix.clone()
} else if path_prefix == "/" { } else if original_name_prefix == "/" {
format!("/{subdir_name}") format!("/{subdir_name}")
} else { } else {
format!("{path_prefix}/{subdir_name}") format!("{original_name_prefix}/{subdir_name}")
}, },
) )
.await?; .await?;
......
...@@ -183,9 +183,9 @@ impl ClientReferenceManifest { ...@@ -183,9 +183,9 @@ impl ClientReferenceManifest {
AssetContent::file( AssetContent::file(
File::from(formatdoc! { File::from(formatdoc! {
r#" r#"
globalThis.__RSC_MANIFEST = globalThis.__RSC_MANIFEST || {{}}; globalThis.__RSC_MANIFEST = globalThis.__RSC_MANIFEST || {{}};
globalThis.__RSC_MANIFEST[{entry_name}] = {manifest} globalThis.__RSC_MANIFEST[{entry_name}] = {manifest}
"#, "#,
entry_name = StringifyJs(&entry_name), entry_name = StringifyJs(&entry_name),
manifest = StringifyJs(&client_reference_manifest_json) manifest = StringifyJs(&client_reference_manifest_json)
}) })
......
...@@ -748,11 +748,9 @@ async function startWatcher(opts: SetupOpts) { ...@@ -748,11 +748,9 @@ async function startWatcher(opts: SetupOpts) {
break break
} }
case 'page-api': { case 'page-api': {
if (isApp) { // We don't throw on ensureOpts.isApp === true here
throw new Error( // since this can happen when app pages make
`mis-matched route type: isApp && page for ${page}` // api requests to page API routes.
)
}
const writtenEndpoint = await processResult( const writtenEndpoint = await processResult(
page, page,
......
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