fix(next-core): align edge chunking context's asset root (#57022)

### 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 <DevChunkingContext as ChunkingContext>::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
This commit is contained in:
OJ Kwon 2023-10-22 12:15:09 -07:00 committed by GitHub
parent cf79cbf3b3
commit 85c3ea8e5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View file

@ -534,7 +534,6 @@ impl Project {
get_edge_chunking_context( get_edge_chunking_context(
self.project_path(), self.project_path(),
self.node_root(), self.node_root(),
self.client_relative_path(),
self.edge_compile_time_info().environment(), self.edge_compile_time_info().environment(),
) )
} }

View file

@ -22,7 +22,6 @@ use turbopack_binding::{
use crate::{ use crate::{
mode::NextMode, mode::NextMode,
next_client::context::get_client_assets_path,
next_config::NextConfig, next_config::NextConfig,
next_import_map::get_next_edge_import_map, next_import_map::get_next_edge_import_map,
next_server::context::ServerContextType, next_server::context::ServerContextType,
@ -155,15 +154,15 @@ pub async fn get_edge_resolve_options_context(
pub fn get_edge_chunking_context( pub fn get_edge_chunking_context(
project_path: Vc<FileSystemPath>, project_path: Vc<FileSystemPath>,
node_root: Vc<FileSystemPath>, node_root: Vc<FileSystemPath>,
client_root: Vc<FileSystemPath>,
environment: Vc<Environment>, environment: Vc<Environment>,
) -> Vc<Box<dyn EcmascriptChunkingContext>> { ) -> Vc<Box<dyn EcmascriptChunkingContext>> {
let output_root = node_root.join("server/edge".to_string());
Vc::upcast( Vc::upcast(
DevChunkingContext::builder( DevChunkingContext::builder(
project_path, project_path,
node_root.join("server/edge".to_string()), output_root,
node_root.join("server/edge/chunks".to_string()), output_root.join("chunks".to_string()),
get_client_assets_path(client_root), output_root.join("assets".to_string()),
environment, environment,
) )
.reference_chunk_source_maps(should_debug("edge")) .reference_chunk_source_maps(should_debug("edge"))