8000 only track react client module loading in dynamicIO prerenders · vercel/next.js@7c082cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c082cb

Browse files
committed
only track react client module loading in dynamicIO prerenders
1 parent 44dfe9e commit 7c082cb

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

packages/next/src/server/app-render/app-render.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,18 +1203,37 @@ async function renderToHTMLOrFlightImpl(
12031203
// to treat chunk/module loading with similar semantics as cache reads to avoid
12041204
// module loading from causing a prerender to abort too early.
12051205

1206+
const shouldTrackModuleLoading = () => {
1207+
if (process.env.NEXT_RUNTIME === 'edge') {
1208+
return false
1209+
} else {
1210+
if (!renderOpts.experimental.dynamicIO) {
1211+
return false
1212+
}
1213+
const workUnitStore = workUnitAsyncStorage.getStore()
1214+
return !!(
1215+
workUnitStore &&
1216+
(workUnitStore.type === 'prerender' || workUnitStore.type === 'cache')
1217+
)
1218+
}
1219+
}
1220+
12061221
const __next_require__: typeof instrumented.require = (...args) => {
12071222
const exportsOrPromise = instrumented.require(...args)
1208-
// requiring an async module returns a promise.
1209-
trackPendingImport(exportsOrPromise)
1223+
if (shouldTrackModuleLoading()) {
1224+
// requiring an async module returns a promise.
1225+
trackPendingImport(exportsOrPromise)
1226+
}
12101227
return exportsOrPromise
12111228
}
12121229
// @ts-expect-error
12131230
globalThis.__next_require__ = __next_require__
12141231

12151232
const __next_chunk_load__: typeof instrumented.loadChunk = (...args) => {
12161233
const loadingChunk = instrumented.loadChunk(...args)
1217-
trackPendingChunkLoad(loadingChunk)
1234+
if (shouldTrackModuleLoading()) {
1235+
trackPendingChunkLoad(loadingChunk)
1236+
}
12181237
return loadingChunk
12191238
}
12201239
// @ts-expect-error

0 commit comments

Comments
 (0)
0