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 {
.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<FileSystemPath>,
pathname: &str,
original_name: &str,
filename: String,
) -> Result<Vc<Box<dyn OutputAsset>>> {
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?
......
......@@ -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?;
......
......@@ -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)
})
......
......@@ -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,
......
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