Unverified Commit b90dcdd0 authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

feat(next-core): set nextconfigoutput correctly (#63848)

### What

PR updates route's template injection correctly sets `nextConfigOutput`.
parent 389ea366
......@@ -20,6 +20,7 @@ use next_core::{
get_client_runtime_entries, ClientContextType, RuntimeEntries,
},
next_client_reference::{ClientReferenceGraph, NextEcmascriptClientReferenceTransition},
next_config::NextConfig,
next_dynamic::NextDynamicTransition,
next_edge::route_regex::get_named_middleware_regex,
next_manifests::{
......@@ -601,6 +602,7 @@ impl AppEndpoint {
&self,
path: Vc<FileSystemPath>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>,
next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> {
let root_layouts = root_layouts.await?;
let config = if root_layouts.is_empty() {
......@@ -624,11 +626,16 @@ impl AppEndpoint {
self.page.clone(),
self.app_project.project().project_path(),
config,
next_config,
))
}
#[turbo_tasks::function]
async fn app_metadata_entry(&self, metadata: MetadataItem) -> Result<Vc<AppEntry>> {
async fn app_metadata_entry(
&self,
metadata: MetadataItem,
next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> {
Ok(get_app_metadata_route_entry(
self.app_project.rsc_module_context(),
self.app_project.edge_rsc_module_context(),
......@@ -636,6 +643,7 @@ impl AppEndpoint {
self.page.clone(),
*self.app_project.project().next_mode().await?,
metadata,
next_config,
))
}
......@@ -648,6 +656,7 @@ impl AppEndpoint {
async fn output(self: Vc<Self>) -> Result<Vc<AppEndpointOutput>> {
let this = self.await?;
let next_config = self.await?.app_project.project().next_config();
let (app_entry, process_client, process_ssr) = match this.ty {
AppEndpointType::Page { ty, loader_tree } => (
self.app_page_entry(loader_tree),
......@@ -657,11 +666,13 @@ impl AppEndpoint {
// NOTE(alexkirsz) For routes, technically, a lot of the following code is not needed,
// as we know we won't have any client references. However, for now, for simplicity's
// sake, we just do the same thing as for pages.
AppEndpointType::Route { path, root_layouts } => {
(self.app_route_entry(path, root_layouts), false, false)
}
AppEndpointType::Route { path, root_layouts } => (
self.app_route_entry(path, root_layouts, next_config),
false,
false,
),
AppEndpointType::Metadata { metadata } => {
(self.app_metadata_entry(metadata), false, false)
(self.app_metadata_entry(metadata, next_config), false, false)
}
};
......
......@@ -18,6 +18,7 @@ use turbopack_binding::{
use crate::{
app_segment_config::NextSegmentConfig,
next_app::{AppEntry, AppPage, AppPath},
next_config::{NextConfig, OutputType},
next_edge::entry::wrap_edge_entry,
parse_segment_config_from_source,
util::{load_next_js_template, NextRuntime},
......@@ -38,6 +39,7 @@ pub async fn get_app_route_entry(
page: AppPage,
project_root: Vc<FileSystemPath>,
original_segment_config: Option<Vc<NextSegmentConfig>>,
next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> {
let segment_from_source = parse_segment_config_from_source(source);
let config = if let Some(original_segment_config) = original_segment_config {
......@@ -62,6 +64,16 @@ pub async fn get_app_route_entry(
const INNER: &str = "INNER_APP_ROUTE";
let output_type = next_config
.await?
.output
.as_ref()
.map(|o| match o {
OutputType::Standalone => "\"standalone\"".to_string(),
OutputType::Export => "\"export\"".to_string(),
})
.unwrap_or_else(|| "\"\"".to_string());
// Load the file from the next.js codebase.
let virtual_source = load_next_js_template(
"app-route.js",
......@@ -77,7 +89,7 @@ pub async fn get_app_route_entry(
"VAR_USERLAND" => INNER.to_string(),
},
indexmap! {
"nextConfigOutput" => "\"\"".to_string(),
"nextConfigOutput" => output_type
},
indexmap! {},
)
......
......@@ -23,6 +23,7 @@ use crate::{
app_structure::MetadataItem,
mode::NextMode,
next_app::{app_entry::AppEntry, app_route_entry::get_app_route_entry, AppPage, PageSegment},
next_config::NextConfig,
parse_segment_config_from_source,
};
......@@ -58,6 +59,7 @@ pub fn get_app_metadata_route_entry(
page: AppPage,
mode: NextMode,
metadata: MetadataItem,
next_config: Vc<NextConfig>,
) -> Vc<AppEntry> {
// Read original source's segment config before replacing source into
// dynamic|static metadata route handler.
......@@ -66,7 +68,7 @@ pub fn get_app_metadata_route_entry(
};
let source = Vc::upcast(FileSource::new(original_path));
let config = parse_segment_config_from_source(source);
let segment_config = parse_segment_config_from_source(source);
get_app_route_entry(
nodejs_context,
......@@ -74,7 +76,8 @@ pub fn get_app_metadata_route_entry(
get_app_metadata_route_source(page.clone(), mode, metadata),
page,
project_root,
Some(config),
Some(segment_config),
next_config,
)
}
......
......@@ -7511,11 +7511,10 @@
"passed": [
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'error'",
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'force-static'",
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute undefined"
],
"failed": [
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute undefined",
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'force-dynamic'"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
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