Unverified Commit 1c2de833 authored by Alex Kirszenberg's avatar Alex Kirszenberg Committed by GitHub

Make `get_client_chunking_context` independent of context (#51928)

The client chunking context must remain the same for a given Next.js compilation. For production builds, we only need to create it once for both the Pages Router and the App Router. As such, it doesn't make sense for it to accept a context type, at least not as an enum. A vector of enums or flags could also work. Considering the only case where the chunking context differes today is the web entry source, we might as well make the web entry source also serve under `_next` (or remove it entirely?).
parent 1fbb5138
......@@ -145,7 +145,6 @@ async fn next_client_transition(
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);
let client_module_options_context = get_client_module_options_context(
project_path,
......@@ -277,7 +276,7 @@ fn next_edge_route_transition(
project_path,
output_path.join("edge"),
output_path.join("edge/chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
edge_compile_time_info.environment(),
)
.reference_chunk_source_maps(should_debug("app_source"))
......@@ -317,7 +316,7 @@ fn next_edge_page_transition(
project_path,
output_path.join("edge-pages"),
output_path.join("edge-pages/chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
edge_compile_time_info.environment(),
)
.layer("ssr")
......@@ -1112,7 +1111,7 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
project_path,
intermediate_output_path,
intermediate_output_path.join("chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
context.compile_time_info().environment(),
)
.layer("ssr")
......@@ -1207,12 +1206,7 @@ impl AppRouteVc {
this.project_path,
this.intermediate_output_path,
this.intermediate_output_path.join("chunks"),
get_client_assets_path(
this.server_root,
Value::new(ClientContextType::App {
app_dir: this.app_dir,
}),
),
get_client_assets_path(this.server_root),
this.context.compile_time_info().environment(),
)
.layer("ssr")
......
......@@ -55,7 +55,6 @@ pub async fn get_fallback_page(
project_path,
dev_server_root,
client_compile_time_info.environment(),
ty,
);
let entries =
get_client_runtime_entries(project_path, env, ty, mode, next_config, execution_context);
......
......@@ -312,20 +312,14 @@ pub fn get_client_asset_context(
#[turbo_tasks::function]
pub fn get_client_chunking_context(
project_path: FileSystemPathVc,
server_root: FileSystemPathVc,
client_root: FileSystemPathVc,
environment: EnvironmentVc,
ty: Value<ClientContextType>,
) -> ChunkingContextVc {
DevChunkingContextVc::builder(
project_path,
server_root,
match ty.into_value() {
ClientContextType::Pages { .. }
| ClientContextType::App { .. }
| ClientContextType::Fallback => server_root.join("/_next/static/chunks"),
ClientContextType::Other => server_root.join("/_chunks"),
},
get_client_assets_path(server_root, ty),
client_root,
client_root.join("/_next/static/chunks"),
get_client_assets_path(client_root),
environment,
)
.hot_module_replacement()
......@@ -333,16 +327,8 @@ pub fn get_client_chunking_context(
}
#[turbo_tasks::function]
pub fn get_client_assets_path(
client_root: FileSystemPathVc,
ty: Value<ClientContextType>,
) -> FileSystemPathVc {
match ty.into_value() {
ClientContextType::Pages { .. }
| ClientContextType::App { .. }
| ClientContextType::Fallback => client_root.join("/_next/static/media"),
ClientContextType::Other => client_root.join("/_assets"),
}
pub fn get_client_assets_path(client_root: FileSystemPathVc) -> FileSystemPathVc {
client_root.join("/_next/static/media")
}
#[turbo_tasks::function]
......
......@@ -50,7 +50,6 @@ impl NextClientChunksTransitionVc {
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);
let client_module_options_context = get_client_module_options_context(
......
......@@ -126,7 +126,6 @@ pub async fn create_page_source(
project_root,
client_root,
client_compile_time_info.environment(),
client_ty,
);
let client_runtime_entries = get_client_runtime_entries(
......@@ -155,10 +154,7 @@ pub async fn create_page_source(
project_root,
node_root.join("edge"),
node_root.join("edge/chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
edge_compile_time_info.environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
......@@ -360,10 +356,7 @@ async fn create_page_source_for_file(
project_path,
node_path,
node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
......@@ -375,10 +368,7 @@ async fn create_page_source_for_file(
project_path,
data_node_path,
data_node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
......@@ -388,7 +378,6 @@ async fn create_page_source_for_file(
project_path,
client_root,
client_context.compile_time_info().environment(),
Value::new(ClientContextType::Pages { pages_dir }),
);
let pathname = pathname_for_path(client_root, client_path, PathType::Page);
......@@ -530,10 +519,7 @@ async fn create_not_found_page_source(
project_path,
node_path,
node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
......@@ -543,7 +529,6 @@ async fn create_not_found_page_source(
project_path,
client_root,
client_context.compile_time_info().environment(),
Value::new(ClientContextType::Pages { pages_dir }),
);
let (page_asset, pathname) =
......
......@@ -129,12 +129,8 @@ pub async fn create_web_entry_source(
mode,
next_config,
);
let chunking_context = get_client_chunking_context(
project_root,
client_root,
compile_time_info.environment(),
ty,
);
let chunking_context =
get_client_chunking_context(project_root, client_root, compile_time_info.environment());
let entries = get_web_runtime_entries(project_root, ty, mode, next_config, execution_context);
let runtime_entries = entries.resolve_entries(context);
......
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