diff --git a/packages/next-swc/crates/next-api/src/app.rs b/packages/next-swc/crates/next-api/src/app.rs index 9b0be3ff869c1..43f09e0bcfab6 100644 --- a/packages/next-swc/crates/next-api/src/app.rs +++ b/packages/next-swc/crates/next-api/src/app.rs @@ -519,18 +519,19 @@ impl AppEndpoint { async fn output(self: Vc) -> Result> { let this = self.await?; - let (app_entry, process_client, process_ssr) = match this.ty { + let (app_entry, process_client, process_ssr, api_route) = match this.ty { AppEndpointType::Page { ty, loader_tree } => ( self.app_page_entry(loader_tree), true, matches!(ty, AppPageEndpointType::Html), + false, ), // 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 } => (self.app_route_entry(path), false, false), + AppEndpointType::Route { path } => (self.app_route_entry(path), false, false, true), AppEndpointType::Metadata { metadata } => { - (self.app_metadata_entry(metadata), false, false) + (self.app_metadata_entry(metadata), false, false, true) } }; @@ -613,7 +614,9 @@ impl AppEndpoint { NextRuntime::NodeJs => { Vc::upcast(this.app_project.project().server_chunking_context()) } - NextRuntime::Edge => this.app_project.project().edge_chunking_context(), + NextRuntime::Edge => { + this.app_project.project().edge_chunking_context(api_route) + } }) } else { None @@ -837,7 +840,7 @@ impl AppEndpoint { let endpoint_output = match runtime { NextRuntime::Edge => { // create edge chunks - let chunking_context = this.app_project.project().edge_chunking_context(); + let chunking_context = this.app_project.project().edge_chunking_context(api_route); let mut evaluatable_assets = this .app_project .edge_rsc_runtime_entries() diff --git a/packages/next-swc/crates/next-api/src/instrumentation.rs b/packages/next-swc/crates/next-api/src/instrumentation.rs index f3cfba2c94a7b..f20bd3e5730af 100644 --- a/packages/next-swc/crates/next-api/src/instrumentation.rs +++ b/packages/next-swc/crates/next-api/src/instrumentation.rs @@ -95,7 +95,7 @@ impl InstrumentationEndpoint { }; evaluatable_assets.push(evaluatable); - let edge_chunking_context = self.project.edge_chunking_context(); + let edge_chunking_context = self.project.edge_chunking_context(true); let edge_files = edge_chunking_context.evaluated_chunk_group_assets( module.ident(), diff --git a/packages/next-swc/crates/next-api/src/middleware.rs b/packages/next-swc/crates/next-api/src/middleware.rs index c3f34375d2f98..7899c6a05cc75 100644 --- a/packages/next-swc/crates/next-api/src/middleware.rs +++ b/packages/next-swc/crates/next-api/src/middleware.rs @@ -97,7 +97,7 @@ impl MiddlewareEndpoint { .context("Entry module must be evaluatable")?; evaluatable_assets.push(evaluatable); - let edge_chunking_context = self.project.edge_chunking_context(); + let edge_chunking_context = self.project.edge_chunking_context(false); let edge_files = edge_chunking_context.evaluated_chunk_group_assets( module.ident(), diff --git a/packages/next-swc/crates/next-api/src/pages.rs b/packages/next-swc/crates/next-api/src/pages.rs index b9bcf89d5baa1..c5b8032d3c32c 100644 --- a/packages/next-swc/crates/next-api/src/pages.rs +++ b/packages/next-swc/crates/next-api/src/pages.rs @@ -795,7 +795,7 @@ impl PageEndpoint { this.pages_project.ssr_module_context(), this.pages_project.edge_ssr_module_context(), this.pages_project.project().server_chunking_context(), - this.pages_project.project().edge_chunking_context(), + this.pages_project.project().edge_chunking_context(false), this.pages_project.ssr_runtime_entries(), this.pages_project.edge_ssr_runtime_entries(), )) @@ -815,7 +815,7 @@ impl PageEndpoint { this.pages_project.ssr_data_module_context(), this.pages_project.edge_ssr_data_module_context(), this.pages_project.project().server_chunking_context(), - this.pages_project.project().edge_chunking_context(), + this.pages_project.project().edge_chunking_context(false), this.pages_project.ssr_data_runtime_entries(), this.pages_project.edge_ssr_data_runtime_entries(), )) @@ -835,7 +835,7 @@ impl PageEndpoint { this.pages_project.api_module_context(), this.pages_project.edge_api_module_context(), this.pages_project.project().server_chunking_context(), - this.pages_project.project().edge_chunking_context(), + this.pages_project.project().edge_chunking_context(true), this.pages_project.ssr_runtime_entries(), this.pages_project.edge_ssr_runtime_entries(), )) diff --git a/packages/next-swc/crates/next-api/src/project.rs b/packages/next-swc/crates/next-api/src/project.rs index 1f4aa206e7993..0d51b458ff784 100644 --- a/packages/next-swc/crates/next-api/src/project.rs +++ b/packages/next-swc/crates/next-api/src/project.rs @@ -571,13 +571,18 @@ impl Project { #[turbo_tasks::function] pub(super) fn edge_chunking_context( self: Vc, + api_route: bool, ) -> Result>> { Ok(get_edge_chunking_context( self.next_mode(), self.project_path(), self.node_root(), self.client_relative_path(), - self.next_config().computed_asset_prefix(), + if api_route { + Vc::cell(Some("blob:".to_string())) + } else { + self.next_config().computed_asset_prefix() + }, self.edge_compile_time_info().environment(), )) } diff --git a/packages/next-swc/crates/next-core/src/next_server/context.rs b/packages/next-swc/crates/next-core/src/next_server/context.rs index a004d0c1e49f2..cf79a2ec5eeb9 100644 --- a/packages/next-swc/crates/next-core/src/next_server/context.rs +++ b/packages/next-swc/crates/next-core/src/next_server/context.rs @@ -616,6 +616,7 @@ pub async fn get_server_module_options_context( next_server_rules.extend(source_transform_rules); let module_options_context = ModuleOptionsContext { + esm_url_rewrite_behavior: Some(UrlRewriteBehavior::Full), ..module_options_context }; let foreign_code_module_options_context = ModuleOptionsContext { diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index ab0c8434b0aeb..6eea207bd58e4 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -1422,7 +1422,7 @@ export default class NextNodeServer extends BaseServer { name: string paths: string[] wasm: { filePath: string; name: string }[] - assets: { filePath: string; name: string }[] + assets?: { filePath: string; name: string }[] } | null { const manifest = this.getMiddlewareManifest() if (!manifest) { @@ -1455,12 +1455,14 @@ export default class NextNodeServer extends BaseServer { ...binding, filePath: join(this.distDir, binding.filePath), })), - assets: (pageInfo.assets ?? []).map((binding) => { - return { - ...binding, - filePath: join(this.distDir, binding.filePath), - } - }), + assets: + pageInfo.assets && + pageInfo.assets.map((binding) => { + return { + ...binding, + filePath: join(this.distDir, binding.filePath), + } + }), } } diff --git a/packages/next/src/server/web/sandbox/fetch-inline-assets.ts b/packages/next/src/server/web/sandbox/fetch-inline-assets.ts index b017c6e8ee752..8d4866f43c3fb 100644 --- a/packages/next/src/server/web/sandbox/fetch-inline-assets.ts +++ b/packages/next/src/server/web/sandbox/fetch-inline-assets.ts @@ -19,8 +19,13 @@ export async function fetchInlineAsset(options: { return } - const hash = inputString.replace('blob:', '') - const asset = options.assets?.find((x) => x.name === hash) + const name = inputString.replace('blob:', '') + const asset = options.assets + ? options.assets.find((x) => x.name === name) + : { + name, + filePath: name, + } if (!asset) { return } diff --git a/test/turbopack-tests-manifest.json b/test/turbopack-tests-manifest.json index d597e15eaaa00..b0d5a820eaa67 100644 --- a/test/turbopack-tests-manifest.json +++ b/test/turbopack-tests-manifest.json @@ -6491,12 +6491,11 @@ "passed": [ "og-api should respond from index", "og-api should throw error when returning a response object in pages/api in node runtime", - "og-api should work in app route in node runtime" - ], - "failed": [ + "og-api should work in app route in node runtime", "og-api should work in app route", "og-api should work in pages/api" ], + "failed": [], "pending": [], "flakey": [], "runtimeError": false