Skip to content

Commit e25c4de

Browse files
Merge branch 'canary' into eliminate-unnecessary-decodes
2 parents 09e71a4 + 4064c64 commit e25c4de

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

packages/next-swc/crates/next-api/src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ impl AppEndpoint {
495495
Vc::upcast(FileSource::new(path)),
496496
self.page.clone(),
497497
self.app_project.project().project_path(),
498+
None,
498499
)
499500
}
500501

packages/next-swc/crates/next-core/src/next_app/app_favicon_entry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,6 @@ pub async fn get_app_route_favicon_entry(
8989
// TODO(alexkirsz) Get this from the metadata?
9090
AppPage(vec![PageSegment::Static("/favicon.ico".to_string())]),
9191
project_root,
92+
None,
9293
))
9394
}

packages/next-swc/crates/next-core/src/next_app/app_route_entry.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,31 @@ use turbopack_binding::{
1616
};
1717

1818
use crate::{
19+
app_segment_config::NextSegmentConfig,
1920
next_app::{AppEntry, AppPage, AppPath},
2021
next_edge::entry::wrap_edge_entry,
2122
parse_segment_config_from_source,
2223
util::{load_next_js_template, NextRuntime},
2324
};
2425

2526
/// Computes the entry for a Next.js app route.
27+
/// # Arguments
28+
///
29+
/// * `original_segment_config` - A next segment config to be specified
30+
/// explicitly for the given source.
31+
/// For some cases `source` may not be the original but the handler (dynamic
32+
/// metadata) which will lose segment config.
2633
#[turbo_tasks::function]
2734
pub async fn get_app_route_entry(
2835
nodejs_context: Vc<ModuleAssetContext>,
2936
edge_context: Vc<ModuleAssetContext>,
3037
source: Vc<Box<dyn Source>>,
3138
page: AppPage,
3239
project_root: Vc<FileSystemPath>,
40+
original_segment_config: Option<Vc<NextSegmentConfig>>,
3341
) -> Result<Vc<AppEntry>> {
34-
let config = parse_segment_config_from_source(source);
42+
let config =
43+
original_segment_config.unwrap_or_else(|| parse_segment_config_from_source(source));
3544
let is_edge = matches!(config.await?.runtime, Some(NextRuntime::Edge));
3645
let context = if is_edge {
3746
edge_context

packages/next-swc/crates/next-core/src/next_app/metadata/route.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use turbo_tasks::{ValueToString, Vc};
99
use turbopack_binding::{
1010
turbo::tasks_fs::{File, FileContent, FileSystemPath},
1111
turbopack::{
12-
core::{asset::AssetContent, source::Source, virtual_source::VirtualSource},
12+
core::{
13+
asset::AssetContent, file_source::FileSource, source::Source,
14+
virtual_source::VirtualSource,
15+
},
1316
ecmascript::utils::StringifyJs,
1417
turbopack::ModuleAssetContext,
1518
},
@@ -20,6 +23,7 @@ use crate::{
2023
app_structure::MetadataItem,
2124
mode::NextMode,
2225
next_app::{app_entry::AppEntry, app_route_entry::get_app_route_entry, AppPage, PageSegment},
26+
parse_segment_config_from_source,
2327
};
2428

2529
/// Computes the route source for a Next.js metadata file.
@@ -55,12 +59,22 @@ pub fn get_app_metadata_route_entry(
5559
mode: NextMode,
5660
metadata: MetadataItem,
5761
) -> Vc<AppEntry> {
62+
// Read original source's segment config before replacing source into
63+
// dynamic|static metadata route handler.
64+
let original_path = match metadata {
65+
MetadataItem::Static { path } | MetadataItem::Dynamic { path } => path,
66+
};
67+
68+
let source = Vc::upcast(FileSource::new(original_path));
69+
let config = parse_segment_config_from_source(source);
70+
5871
get_app_route_entry(
5972
nodejs_context,
6073
edge_context,
6174
get_app_metadata_route_source(page.clone(), mode, metadata),
6275
page,
6376
project_root,
77+
Some(config),
6478
)
6579
}
6680

test/turbopack-tests-manifest.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,11 +3774,10 @@
37743774
"app dir - metadata dynamic routes social image routes should support params as argument in dynamic routes",
37753775
"app dir - metadata dynamic routes text routes should handle robots.[ext] dynamic routes",
37763776
"app dir - metadata dynamic routes text routes should handle sitemap.[ext] dynamic routes",
3777-
"app dir - metadata dynamic routes text routes should not throw if client components are imported but not used"
3778-
],
3779-
"failed": [
3777+
"app dir - metadata dynamic routes text routes should not throw if client components are imported but not used",
37803778
"app dir - metadata dynamic routes social image routes should handle custom fonts in both edge and nodejs runtime"
37813779
],
3780+
"failed": [],
37823781
"pending": [],
37833782
"flakey": [],
37843783
"runtimeError": false

0 commit comments

Comments
 (0)