Skip to content

Commit 7834959

Browse files
committed
turbopack: delay deferred graph loading until callback gate
1 parent 296047c commit 7834959

File tree

2 files changed

+12
-8
lines changed
  • crates/next-napi-bindings/src/next_api
  • packages/next/src/build/turbopack-build

2 files changed

+12
-8
lines changed

crates/next-napi-bindings/src/next_api/project.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,12 @@ async fn output_assets_operation(
11231123

11241124
let routes_hashes_manifest = routes_hashes_manifest_asset_if_enabled(project).await?;
11251125

1126-
project.whole_app_module_graphs().as_side_effect().await?;
1126+
// Per-write debug_build_paths are partial writes (used by deferred entries
1127+
// first pass). Avoid eagerly computing the whole app graph there so deferred
1128+
// modules are not loaded before the callback gate.
1129+
if debug_build_paths.is_none() {
1130+
project.whole_app_module_graphs().as_side_effect().await?;
1131+
}
11271132

11281133
Ok(Vc::cell(
11291134
output_assets

packages/next/src/build/turbopack-build/impl.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export async function turbopackBuild(): Promise<{
244244
}
245245

246246
// For deferred entries, we use debugBuildPaths to control which routes are built
247-
// First build excludes deferred entries, second build includes only deferred entries
247+
// in two phases around onBeforeDeferredEntries.
248248
const nonDeferredBuildPaths =
249249
hasDeferredEntries && NextBuildContext.appDir
250250
? getNonDeferredBuildPaths(
@@ -309,14 +309,13 @@ export async function turbopackBuild(): Promise<{
309309
: NextBuildContext.debugBuildPaths
310310
const firstPassDebugBuildPaths = firstPassBuildPaths ?? undefined
311311

312-
// In deferred mode, keep the first pass filter on the project and apply the
313-
// deferred filter as a per-write override in the second pass.
312+
// In deferred mode, the first-pass filter must be a per-write override so the
313+
// native layer can treat it as a partial write and avoid eager full-app graph
314+
// work before onBeforeDeferredEntries is called.
314315
const projectDebugBuildPaths = hasDeferredEntries
315-
? firstPassDebugBuildPaths
316-
: NextBuildContext.debugBuildPaths
317-
const firstPassWriteDebugBuildPaths = hasDeferredEntries
318316
? undefined
319-
: firstPassDebugBuildPaths
317+
: NextBuildContext.debugBuildPaths
318+
const firstPassWriteDebugBuildPaths = firstPassDebugBuildPaths
320319

321320
const project = await bindings.turbo.createProject(
322321
{

0 commit comments

Comments
 (0)