Unverified Commit 7c67b121 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

fix route groups in app_structure (#53247)

### What?

the key shouldn't include route groups
parent 37bb09d3
......@@ -241,14 +241,14 @@ async fn prepare_entrypoints_for_js(
let entrypoints = entrypoints
.await?
.iter()
.map(|(key, &value)| {
.map(|(key, value)| {
let key = key.to_string();
async move {
let value = match value {
Entrypoint::AppPage { loader_tree } => EntrypointForJs::AppPage {
let value = match *value {
Entrypoint::AppPage { loader_tree, .. } => EntrypointForJs::AppPage {
loader_tree: prepare_loader_tree_for_js(project_path, loader_tree).await?,
},
Entrypoint::AppRoute { path } => EntrypointForJs::AppRoute {
Entrypoint::AppRoute { path, .. } => EntrypointForJs::AppRoute {
path: fs_path_to_path(project_path, path).await?,
},
};
......
......@@ -342,7 +342,8 @@ impl AppProject {
.map(|(pathname, app_entrypoint)| async {
Ok((
pathname.clone(),
*app_entry_point_to_route(self, *app_entrypoint, pathname.clone()).await?,
*app_entry_point_to_route(self, app_entrypoint.clone(), pathname.clone())
.await?,
))
})
.try_join()
......@@ -360,7 +361,10 @@ pub async fn app_entry_point_to_route(
pathname: String,
) -> Vc<Route> {
match entrypoint {
AppEntrypoint::AppPage { loader_tree } => Route::AppPage {
AppEntrypoint::AppPage {
original_name,
loader_tree,
} => Route::AppPage {
html_endpoint: Vc::upcast(
AppEndpoint {
ty: AppEndpointType::Page {
......@@ -369,6 +373,7 @@ pub async fn app_entry_point_to_route(
},
app_project,
pathname: pathname.clone(),
original_name: original_name.clone(),
}
.cell(),
),
......@@ -380,16 +385,21 @@ pub async fn app_entry_point_to_route(
},
app_project,
pathname,
original_name,
}
.cell(),
),
},
AppEntrypoint::AppRoute { path } => Route::AppRoute {
AppEntrypoint::AppRoute {
original_name,
path,
} => Route::AppRoute {
endpoint: Vc::upcast(
AppEndpoint {
ty: AppEndpointType::Route { path },
app_project,
pathname: pathname.clone(),
pathname,
original_name,
}
.cell(),
),
......@@ -420,6 +430,7 @@ struct AppEndpoint {
ty: AppEndpointType,
app_project: Vc<AppProject>,
pathname: String,
original_name: String,
}
#[turbo_tasks::value_impl]
......@@ -440,6 +451,7 @@ impl AppEndpoint {
loader_tree,
self.app_project.app_dir(),
self.pathname.clone(),
self.original_name.clone(),
self.app_project.project().project_path(),
)
}
......@@ -451,6 +463,7 @@ impl AppEndpoint {
self.app_project.edge_rsc_module_context(),
Vc::upcast(FileSource::new(path)),
self.pathname.clone(),
self.original_name.clone(),
self.app_project.project().project_path(),
)
}
......
......@@ -189,21 +189,29 @@ pub async fn get_app_entries(
.iter()
.map(|(pathname, entrypoint)| async move {
Ok(match entrypoint {
Entrypoint::AppPage { loader_tree } => get_app_page_entry(
Entrypoint::AppPage {
original_name,
loader_tree,
} => get_app_page_entry(
rsc_context,
// TODO add edge support
rsc_context,
*loader_tree,
app_dir,
pathname.clone(),
original_name.clone(),
project_root,
),
Entrypoint::AppRoute { path } => get_app_route_entry(
Entrypoint::AppRoute {
original_name,
path,
} => get_app_route_entry(
rsc_context,
// TODO add edge support
rsc_context,
Vc::upcast(FileSource::new(*path)),
pathname.clone(),
original_name.clone(),
project_root,
),
})
......
......@@ -611,8 +611,11 @@ pub async fn create_app_source(
let entrypoints = entrypoints.await?;
let mut sources: Vec<_> = entrypoints
.iter()
.map(|(pathname, &loader_tree)| match loader_tree {
Entrypoint::AppPage { loader_tree } => create_app_page_source_for_route(
.map(|(pathname, entrypoint)| match *entrypoint {
Entrypoint::AppPage {
original_name: _,
loader_tree,
} => create_app_page_source_for_route(
pathname.clone(),
loader_tree,
context_ssr,
......@@ -626,7 +629,10 @@ pub async fn create_app_source(
output_path,
render_data,
),
Entrypoint::AppRoute { path } => create_app_route_source_for_route(
Entrypoint::AppRoute {
original_name: _,
path,
} => create_app_route_source_for_route(
pathname.clone(),
path,
context_ssr,
......@@ -646,7 +652,11 @@ pub async fn create_app_source(
)))
.collect();
if let Some(&Entrypoint::AppPage { loader_tree }) = entrypoints.get("/_not-found") {
if let Some(&Entrypoint::AppPage {
original_name: _,
loader_tree,
}) = entrypoints.get("/_not-found")
{
if loader_tree.await?.components.await?.not_found.is_some() {
// Only add a source for the app 404 page if a top-level not-found page is
// defined. Otherwise, the 404 page is handled by the pages logic.
......
......@@ -85,6 +85,7 @@ pub async fn get_app_route_favicon_entry(
Vc::upcast(source),
// TODO(alexkirsz) Get this from the metadata?
"/favicon.ico".to_string(),
"/favicon.ico".to_string(),
project_root,
))
}
......@@ -34,6 +34,7 @@ pub async fn get_app_page_entry(
loader_tree: Vc<LoaderTree>,
app_dir: Vc<FileSystemPath>,
pathname: String,
original_name: String,
project_root: Vc<FileSystemPath>,
) -> Result<Vc<AppEntry>> {
let config = parse_segment_config_from_loader_tree(loader_tree, Vc::upcast(nodejs_context));
......@@ -81,7 +82,7 @@ pub async fn get_app_page_entry(
// NOTE(alexkirsz) Keep in sync with
// next.js/packages/next/src/build/webpack/loaders/next-app-loader.ts
// TODO(alexkirsz) Support custom global error.
let original_name = get_original_page_name(&pathname);
let original_name = get_original_page_name(&original_name);
writedoc!(
result,
......@@ -89,7 +90,7 @@ pub async fn get_app_page_entry(
export const tree = {loader_tree_code}
export const pages = {pages}
export {{ default as GlobalError }} from 'next/dist/client/components/error-boundary'
export const originalPathname = {pathname}
export const originalPathname = {original_name}
export const __next_app__ = {{
require: __turbopack_require__,
loadChunk: __turbopack_load__,
......@@ -98,7 +99,7 @@ pub async fn get_app_page_entry(
export * from 'next/dist/server/app-render/entry-base'
"#,
pages = StringifyJs(&pages),
pathname = StringifyJs(&original_name),
original_name = StringifyJs(&original_name),
)?;
let file = File::from(result.build());
......
......@@ -31,6 +31,7 @@ pub async fn get_app_route_entry(
edge_context: Vc<ModuleAssetContext>,
source: Vc<Box<dyn Source>>,
pathname: String,
original_name: String,
project_root: Vc<FileSystemPath>,
) -> Result<Vc<AppEntry>> {
let config = parse_segment_config_from_source(
......@@ -49,7 +50,7 @@ pub async fn get_app_route_entry(
let mut result = RopeBuilder::default();
let kind = "app-route";
let original_name = get_original_route_name(&pathname);
let original_name = get_original_route_name(&original_name);
let path = source.ident().path();
let options = AppRouteRouteModuleOptions {
......
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