Unverified Commit 889deb0a authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

turbopack: only add the Pages client entry when Pages routes exist (#100896)

## Summary

Only add the Pages Router client entry to the whole-app module graph
when Pages Router endpoints will be emitted. Reuse the existing `/_app`
endpoint condition.

App Router–only builds otherwise resolve, parse, and analyze the Pages
client graph without emitting it. Pages and mixed-router builds keep
their existing entry.

## Verification

- Pages-only change compiles independently (`cargo check -p next-api`).
- App-only fixture graph: 1,074 → 955 modules. Mixed fixture builds and
serves its Pages route.

Separate from the AST cleanup in #100871; these PRs are independent.

<!-- NEXT_JS_LLM -->

<!-- I AM A HUMAN AUTHOR -->

<!-- fleet 20689ccb-eff4-4cad-b89e-beeccbd8caa3 -->

---------
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 6198e2a7
......@@ -2746,13 +2746,36 @@ impl Project {
Ok(any_output_changed(roots, path, false))
}
/// Whether Pages Router endpoints are emitted, which is exactly when `get_all_endpoint_groups`
/// adds the `/_app` endpoint (i.e. there is at least one Pages Router route).
#[turbo_tasks::function]
pub async fn contains_pages_endpoints(self: Vc<Self>) -> Result<Vc<bool>> {
Ok(Vc::cell(
self.get_all_endpoint_groups(/* app_dir_only */ false)
.await?
.iter()
.any(|(key, _)| matches!(key, EndpointGroupKey::PagesApp)),
))
}
#[turbo_tasks::function]
pub async fn client_main_modules(self: Vc<Self>) -> Result<Vc<GraphEntries>> {
let pages_project = self.pages_project();
let mut chunk_groups = vec![ChunkGroupEntry::Entry {
modules: vec![pages_project.client_main_module().to_resolved().await?],
heuristics: EntryHeuristics::high_priority(),
}];
let mut chunk_groups = Vec::new();
// The Pages Router client runtime is only needed when Pages endpoints are emitted.
// Otherwise including it would pull the whole Pages Router client graph into the
// whole-app module graph for nothing.
if *self.contains_pages_endpoints().await? {
chunk_groups.push(ChunkGroupEntry::Entry {
modules: vec![
self.pages_project()
.client_main_module()
.to_resolved()
.await?,
],
heuristics: EntryHeuristics::high_priority(),
});
}
if let Some(app_project) = *self.app_project().await? {
chunk_groups.push(ChunkGroupEntry::Entry {
......
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