From 85c3ea8e5b7c03fd9d122d212e90a64be2034aed Mon Sep 17 00:00:00 2001 From: OJ Kwon <1210596+kwonoj@users.noreply.github.com> Date: Sun, 22 Oct 2023 12:15:09 -0700 Subject: [PATCH] fix(next-core): align edge chunking context's asset root (#57022) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What? If there's a static asset with edge runtime config, turbopack will bail with ``` тип ModuleBuildError: Code generation for chunk item errored An error occurred while generating the chunk item [project]/test/e2e/app-dir/metadata/app/icon.svg (static, edge rsc) Caused by: - expected output_root to contain asset path Debug info: - An error occurred while generating the chunk item [project]/test/e2e/app-dir/metadata/app/icon.svg (static, edge rsc) - Execution of ::asset_url failed - expected output_root to contain asset path ``` Since we creates chunking context for the edge with different output_root and asset_root, by using asset_root to be client_root. The other places creating context with `DevChunkingContext` don't do this, PR simply adjusting root to be output_root. For the server's chunking context it actually accepts client_root and set the asseturl with client root instead. However not sure if that's what we want with devchunkingcontext. This is part of metadata fixes for the test; however edge rendering still doesn't work so test doesn't pass yet. Closes WEB-1798 --- packages/next-swc/crates/next-api/src/project.rs | 1 - .../next-swc/crates/next-core/src/next_edge/context.rs | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/next-swc/crates/next-api/src/project.rs b/packages/next-swc/crates/next-api/src/project.rs index 1bc9e00e65..ce66f61ef3 100644 --- a/packages/next-swc/crates/next-api/src/project.rs +++ b/packages/next-swc/crates/next-api/src/project.rs @@ -534,7 +534,6 @@ impl Project { get_edge_chunking_context( self.project_path(), self.node_root(), - self.client_relative_path(), self.edge_compile_time_info().environment(), ) } diff --git a/packages/next-swc/crates/next-core/src/next_edge/context.rs b/packages/next-swc/crates/next-core/src/next_edge/context.rs index 95042352da..95347ce8c9 100644 --- a/packages/next-swc/crates/next-core/src/next_edge/context.rs +++ b/packages/next-swc/crates/next-core/src/next_edge/context.rs @@ -22,7 +22,6 @@ use turbopack_binding::{ use crate::{ mode::NextMode, - next_client::context::get_client_assets_path, next_config::NextConfig, next_import_map::get_next_edge_import_map, next_server::context::ServerContextType, @@ -155,15 +154,15 @@ pub async fn get_edge_resolve_options_context( pub fn get_edge_chunking_context( project_path: Vc, node_root: Vc, - client_root: Vc, environment: Vc, ) -> Vc> { + let output_root = node_root.join("server/edge".to_string()); Vc::upcast( DevChunkingContext::builder( project_path, - node_root.join("server/edge".to_string()), - node_root.join("server/edge/chunks".to_string()), - get_client_assets_path(client_root), + output_root, + output_root.join("chunks".to_string()), + output_root.join("assets".to_string()), environment, ) .reference_chunk_source_maps(should_debug("edge"))