Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()),
));
Expand All @@ -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)]
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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?
Expand Down
8 changes: 4 additions & 4 deletions packages/next-swc/crates/next-core/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
8 changes: 3 additions & 5 deletions packages/next/src/server/lib/router-utils/setup-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading