Skip to content

Commit 84215b3

Browse files
committed
debug logs
1 parent 565a2b8 commit 84215b3

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,11 +3243,18 @@ async function renderWithRestartOnCacheMissInDev(
32433243
// where sync IO does not cause aborts, so it's okay if it happens before render.
32443244
const initialRscPayload = await getPayload(requestStore)
32453245

3246+
console.log('\n\n##########################################################')
3247+
console.log(
3248+
`[app-render] :: rendering ${requestStore.url.pathname} (${ctx.workStore.route})\n`
3249+
)
32463250
const maybeInitialServerStream = await workUnitAsyncStorage.run(
32473251
requestStore,
32483252
() =>
32493253
pipelineInSequentialTasks(
32503254
() => {
3255+
console.log(
3256+
'=================== [initial] Static ==================='
3257+
)
32513258
// Static stage
32523259
initialStageController.advanceStage(RenderStage.Static)
32533260

@@ -3285,6 +3292,9 @@ async function renderWithRestartOnCacheMissInDev(
32853292

32863293
if (initialStageController.currentStage === RenderStage.Abandoned) {
32873294
// If we abandoned the render in the static stage, we won't proceed further.
3295+
console.log(
3296+
'[app-render] initial render was abandoned due to sync IO in the static stage'
3297+
)
32883298
return null
32893299
}
32903300

@@ -3296,10 +3306,17 @@ async function renderWithRestartOnCacheMissInDev(
32963306
// Regardless of whether we are going to abandon this
32973307
// render we need the unblock runtime b/c it's essential
32983308
// filling caches.
3309+
console.log(
3310+
'[app-render] abandoning initial render due to a cache miss in the static stage'
3311+
)
32993312
initialStageController.abandonRender()
33003313
return null
33013314
}
33023315

3316+
console.log(
3317+
'=================== [initial] Runtime ==================='
3318+
)
3319+
33033320
initialStageController.advanceStage(RenderStage.Runtime)
33043321
return stream
33053322
},
@@ -3309,6 +3326,14 @@ async function renderWithRestartOnCacheMissInDev(
33093326
stream === null ||
33103327
initialStageController.currentStage === RenderStage.Abandoned
33113328
) {
3329+
if (
3330+
stream !== null &&
3331+
initialStageController.currentStage === RenderStage.Abandoned
3332+
) {
3333+
console.log(
3334+
'[app-render] initial render was abandoned due to sync IO in the runtime stage'
3335+
)
3336+
}
33123337
// If we abandoned the render in the static or runtime stage, we won't proceed further.
33133338
return null
33143339
}
@@ -3318,10 +3343,16 @@ async function renderWithRestartOnCacheMissInDev(
33183343
// We won't advance the stage, and thus leave dynamic APIs hanging,
33193344
// because they won't be cached anyway, so it'd be wasted work.
33203345
if (cacheSignal.hasPendingReads()) {
3346+
console.log(
3347+
'[app-render] abandoning initial render due to a cache miss in the runtime stage'
3348+
)
33213349
initialStageController.abandonRender()
33223350
return null
33233351
}
33243352

3353+
console.log(
3354+
'=================== [initial] Dynamic ==================='
3355+
)
33253356
// Regardless of whether we are going to abandon this
33263357
// render we need the unblock runtime b/c it's essential
33273358
// filling caches.
@@ -3364,6 +3395,8 @@ async function renderWithRestartOnCacheMissInDev(
33643395
await cacheSignal.cacheReady()
33653396
initialReactController.abort()
33663397

3398+
console.log('*********** restarting render ***********')
3399+
33673400
//===============================================
33683401
// Final render (restarted)
33693402
//===============================================
@@ -3411,6 +3444,7 @@ async function renderWithRestartOnCacheMissInDev(
34113444
const finalServerStream = await workUnitAsyncStorage.run(requestStore, () =>
34123445
pipelineInSequentialTasks(
34133446
() => {
3447+
console.log('=================== [final] Static ===================')
34143448
// Static stage
34153449
finalStageController.advanceStage(RenderStage.Static)
34163450

@@ -3437,11 +3471,23 @@ async function renderWithRestartOnCacheMissInDev(
34373471
return continuationStream
34383472
},
34393473
(stream) => {
3474+
if (finalStageController.currentStage !== RenderStage.Static) {
3475+
console.log(
3476+
`[app-render] stage was advanced to ${RenderStage[finalStageController.currentStage]} before reaching the runtime stage`
3477+
)
3478+
}
3479+
console.log('=================== [final] Runtime ===================')
34403480
// Runtime stage
34413481
finalStageController.advanceStage(RenderStage.Runtime)
34423482
return stream
34433483
},
34443484
(stream) => {
3485+
if (finalStageController.currentStage !== RenderStage.Runtime) {
3486+
console.log(
3487+
`[app-render] stage was advanced to ${RenderStage[finalStageController.currentStage]} before reaching the dynamic stage`
3488+
)
3489+
}
3490+
console.log('=================== [final] Dynamic ===================')
34453491
// Dynamic stage
34463492
finalStageController.advanceStage(RenderStage.Dynamic)
34473493
return stream
@@ -3650,6 +3696,38 @@ async function spawnStaticShellValidationInDev(
36503696
workStore,
36513697
} = ctx
36523698

3699+
{
3700+
const logChunks = (chunks: Array<Uint8Array>) => {
3701+
const textDecoder = new TextDecoder()
3702+
for (const chunk of chunks) {
3703+
console.log(textDecoder.decode(chunk))
3704+
}
3705+
}
3706+
console.log(`Static chunks (${staticServerChunks.length})`)
3707+
console.log('------------------------')
3708+
logChunks(staticServerChunks)
3709+
console.log('------------------------')
3710+
3711+
const runtimeOnlyChunks = runtimeServerChunks.slice(
3712+
staticServerChunks.length
3713+
)
3714+
console.log('\n')
3715+
console.log(`Runtime chunks (${runtimeOnlyChunks.length})`)
3716+
console.log('------------------------')
3717+
logChunks(runtimeOnlyChunks)
3718+
console.log('------------------------')
3719+
3720+
const dynamicOnlyChunks = dynamicServerChunks.slice(
3721+
runtimeServerChunks.length
3722+
)
3723+
console.log('\n')
3724+
console.log(`Dynamic chunks (${dynamicOnlyChunks.length})`)
3725+
console.log('------------------------')
3726+
logChunks(dynamicOnlyChunks)
3727+
console.log('------------------------')
3728+
console.log('\n\n')
3729+
}
3730+
36533731
const { allowEmptyStaticShell = false } = renderOpts
36543732

36553733
const rootParams = getRootParams(

packages/next/src/server/app-render/staged-rendering.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,23 @@ export class StagedRenderingController {
8686
// so we want a slightly different flow.
8787
// See the implementation of `abandonRenderImpl` for more explanation.
8888
if (this.mayAbandon) {
89+
console.log(
90+
'========= initial render: abandoning due to sync IO ========='
91+
)
92+
console.log(
93+
`current stage: ${RenderStage[this.currentStage]}, error: ${reason.message}`
94+
)
8995
return this.abandonRenderImpl()
9096
}
9197

9298
// If we're in the final render, we cannot abandon it. We need to advance to the Dynamic stage
9399
// and capture the interruption reason.
100+
console.log(
101+
'========= final render: advancing stage to Dynamic due to sync IO ========='
102+
)
103+
console.log(
104+
`current stage: ${RenderStage[this.currentStage]}, error: ${reason.message}`
105+
)
94106
switch (this.currentStage) {
95107
case RenderStage.Static: {
96108
this.staticInterruptReason = reason
@@ -198,6 +210,7 @@ export class StagedRenderingController {
198210

199211
/** Fire the `onStage` listeners for the runtime stage and unblock any promises waiting for it. */
200212
private resolveRuntimeStage() {
213+
console.log('[staged-rendering] resolving runtime stage')
201214
const runtimeListeners = this.runtimeStageListeners
202215
for (let i = 0; i < runtimeListeners.length; i++) {
203216
runtimeListeners[i]()
@@ -208,6 +221,7 @@ export class StagedRenderingController {
208221

209222
/** Fire the `onStage` listeners for the dynamic stage and unblock any promises waiting for it. */
210223
private resolveDynamicStage() {
224+
console.log('[staged-rendering] resolving dynamic stage')
211225
const dynamicListeners = this.dynamicStageListeners
212226
for (let i = 0; i < dynamicListeners.length; i++) {
213227
dynamicListeners[i]()

0 commit comments

Comments
 (0)