Skip to content

Commit 15602df

Browse files
committed
debug logs
1 parent 9ff5927 commit 15602df

File tree

4 files changed

+106
-10
lines changed

4 files changed

+106
-10
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,6 +3248,9 @@ async function renderWithRestartOnCacheMissInDev(
32483248
() =>
32493249
pipelineInSequentialTasks(
32503250
() => {
3251+
console.log(
3252+
'=================== [initial] Static ==================='
3253+
)
32513254
// Static stage
32523255
initialStageController.advanceStage(RenderStage.Static)
32533256

@@ -3285,6 +3288,9 @@ async function renderWithRestartOnCacheMissInDev(
32853288

32863289
if (initialStageController.currentStage === RenderStage.Abandoned) {
32873290
// If we abandoned the render in the static stage, we won't proceed further.
3291+
console.log(
3292+
'[app-render] initial render was abandoned due to sync IO in the static stage'
3293+
)
32883294
return null
32893295
}
32903296

@@ -3296,10 +3302,17 @@ async function renderWithRestartOnCacheMissInDev(
32963302
// Regardless of whether we are going to abandon this
32973303
// render we need the unblock runtime b/c it's essential
32983304
// filling caches.
3305+
console.log(
3306+
'[app-render] abandoning initial render due to a cache miss in the static stage'
3307+
)
32993308
initialStageController.abandonRender()
33003309
return null
33013310
}
33023311

3312+
console.log(
3313+
'=================== [initial] Runtime ==================='
3314+
)
3315+
33033316
initialStageController.advanceStage(RenderStage.Runtime)
33043317
return stream
33053318
},
@@ -3309,6 +3322,14 @@ async function renderWithRestartOnCacheMissInDev(
33093322
stream === null ||
33103323
initialStageController.currentStage === RenderStage.Abandoned
33113324
) {
3325+
if (
3326+
stream !== null &&
3327+
initialStageController.currentStage === RenderStage.Abandoned
3328+
) {
3329+
console.log(
3330+
'[app-render] initial render was abandoned due to sync IO in the runtime stage'
3331+
)
3332+
}
33123333
// If we abandoned the render in the static or runtime stage, we won't proceed further.
33133334
return null
33143335
}
@@ -3318,10 +3339,16 @@ async function renderWithRestartOnCacheMissInDev(
33183339
// We won't advance the stage, and thus leave dynamic APIs hanging,
33193340
// because they won't be cached anyway, so it'd be wasted work.
33203341
if (cacheSignal.hasPendingReads()) {
3342+
console.log(
3343+
'[app-render] abandoning initial render due to a cache miss in the runtime stage'
3344+
)
33213345
initialStageController.abandonRender()
33223346
return null
33233347
}
33243348

3349+
console.log(
3350+
'=================== [initial] Dynamic ==================='
3351+
)
33253352
// Regardless of whether we are going to abandon this
33263353
// render we need the unblock runtime b/c it's essential
33273354
// filling caches.
@@ -3364,6 +3391,8 @@ async function renderWithRestartOnCacheMissInDev(
33643391
await cacheSignal.cacheReady()
33653392
initialReactController.abort()
33663393

3394+
console.log('*********** restarting render ***********')
3395+
33673396
//===============================================
33683397
// Final render (restarted)
33693398
//===============================================
@@ -3411,6 +3440,7 @@ async function renderWithRestartOnCacheMissInDev(
34113440
const finalServerStream = await workUnitAsyncStorage.run(requestStore, () =>
34123441
pipelineInSequentialTasks(
34133442
() => {
3443+
console.log('=================== [final] Static ===================')
34143444
// Static stage
34153445
finalStageController.advanceStage(RenderStage.Static)
34163446

@@ -3437,11 +3467,23 @@ async function renderWithRestartOnCacheMissInDev(
34373467
return continuationStream
34383468
},
34393469
(stream) => {
3470+
if (finalStageController.currentStage !== RenderStage.Static) {
3471+
console.log(
3472+
`[app-render] stage was advanced to ${RenderStage[finalStageController.currentStage]} before reaching the runtime stage`
3473+
)
3474+
}
3475+
console.log('=================== [final] Runtime ===================')
34403476
// Runtime stage
34413477
finalStageController.advanceStage(RenderStage.Runtime)
34423478
return stream
34433479
},
34443480
(stream) => {
3481+
if (finalStageController.currentStage !== RenderStage.Runtime) {
3482+
console.log(
3483+
`[app-render] stage was advanced to ${RenderStage[finalStageController.currentStage]} before reaching the dynamic stage`
3484+
)
3485+
}
3486+
console.log('=================== [final] Dynamic ===================')
34453487
// Dynamic stage
34463488
finalStageController.advanceStage(RenderStage.Dynamic)
34473489
return stream
@@ -3650,6 +3692,32 @@ async function spawnStaticShellValidationInDev(
36503692
workStore,
36513693
} = ctx
36523694

3695+
{
3696+
const logChunks = (chunks: Array<Uint8Array>) => {
3697+
const textDecoder = new TextDecoder()
3698+
for (const chunk of chunks) {
3699+
console.log(textDecoder.decode(chunk))
3700+
}
3701+
}
3702+
console.log('Static chunks')
3703+
console.log('------------------------')
3704+
logChunks(staticServerChunks)
3705+
console.log('------------------------')
3706+
3707+
console.log('\n')
3708+
console.log('Runtime chunks')
3709+
console.log('------------------------')
3710+
logChunks(runtimeServerChunks.slice(staticServerChunks.length))
3711+
console.log('------------------------')
3712+
3713+
console.log('\n')
3714+
console.log('Dynamic chunks')
3715+
console.log('------------------------')
3716+
logChunks(dynamicServerChunks.slice(runtimeServerChunks.length))
3717+
console.log('------------------------')
3718+
console.log('\n\n')
3719+
}
3720+
36533721
const { allowEmptyStaticShell = false } = renderOpts
36543722

36553723
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]()
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
export default async function Page(props: {
22
params: Promise<{ top: string; bottom: string }>
33
}) {
4-
return (
5-
<p>
6-
Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
7-
</p>
8-
)
4+
try {
5+
console.log('/none/[top]/wrapped/[bottom]/page.tsx :: awaiting params')
6+
return (
7+
<p>
8+
Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
9+
</p>
10+
)
11+
} finally {
12+
console.log(
13+
'/none/[top]/wrapped/[bottom]/page.tsx :: finished awaiting params'
14+
)
15+
}
916
}
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
export default async function Page(props: {
22
params: Promise<{ top: string; bottom: string }>
33
}) {
4-
return (
5-
<p>
6-
Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
7-
</p>
8-
)
4+
try {
5+
console.log('/partial/[top]/wrapped/[bottom]/page.tsx :: awaiting params')
6+
return (
7+
<p>
8+
Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
9+
</p>
10+
)
11+
} finally {
12+
console.log(
13+
'/partial/[top]/wrapped/[bottom]/page.tsx :: finished awaiting params'
14+
)
15+
}
916
}

0 commit comments

Comments
 (0)