Skip to content

Commit 21051bd

Browse files
committed
debug logs
1 parent 565a2b8 commit 21051bd

File tree

6 files changed

+132
-20
lines changed

6 files changed

+132
-20
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,11 +3243,16 @@ 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('##########################################################')
3247+
console.log(`[app-render] :: rendering ${requestStore.url.pathname}`)
32463248
const maybeInitialServerStream = await workUnitAsyncStorage.run(
32473249
requestStore,
32483250
() =>
32493251
pipelineInSequentialTasks(
32503252
() => {
3253+
console.log(
3254+
'=================== [initial] Static ==================='
3255+
)
32513256
// Static stage
32523257
initialStageController.advanceStage(RenderStage.Static)
32533258

@@ -3285,6 +3290,9 @@ async function renderWithRestartOnCacheMissInDev(
32853290

32863291
if (initialStageController.currentStage === RenderStage.Abandoned) {
32873292
// If we abandoned the render in the static stage, we won't proceed further.
3293+
console.log(
3294+
'[app-render] initial render was abandoned due to sync IO in the static stage'
3295+
)
32883296
return null
32893297
}
32903298

@@ -3296,10 +3304,17 @@ async function renderWithRestartOnCacheMissInDev(
32963304
// Regardless of whether we are going to abandon this
32973305
// render we need the unblock runtime b/c it's essential
32983306
// filling caches.
3307+
console.log(
3308+
'[app-render] abandoning initial render due to a cache miss in the static stage'
3309+
)
32993310
initialStageController.abandonRender()
33003311
return null
33013312
}
33023313

3314+
console.log(
3315+
'=================== [initial] Runtime ==================='
3316+
)
3317+
33033318
initialStageController.advanceStage(RenderStage.Runtime)
33043319
return stream
33053320
},
@@ -3309,6 +3324,14 @@ async function renderWithRestartOnCacheMissInDev(
33093324
stream === null ||
33103325
initialStageController.currentStage === RenderStage.Abandoned
33113326
) {
3327+
if (
3328+
stream !== null &&
3329+
initialStageController.currentStage === RenderStage.Abandoned
3330+
) {
3331+
console.log(
3332+
'[app-render] initial render was abandoned due to sync IO in the runtime stage'
3333+
)
3334+
}
33123335
// If we abandoned the render in the static or runtime stage, we won't proceed further.
33133336
return null
33143337
}
@@ -3318,10 +3341,16 @@ async function renderWithRestartOnCacheMissInDev(
33183341
// We won't advance the stage, and thus leave dynamic APIs hanging,
33193342
// because they won't be cached anyway, so it'd be wasted work.
33203343
if (cacheSignal.hasPendingReads()) {
3344+
console.log(
3345+
'[app-render] abandoning initial render due to a cache miss in the runtime stage'
3346+
)
33213347
initialStageController.abandonRender()
33223348
return null
33233349
}
33243350

3351+
console.log(
3352+
'=================== [initial] Dynamic ==================='
3353+
)
33253354
// Regardless of whether we are going to abandon this
33263355
// render we need the unblock runtime b/c it's essential
33273356
// filling caches.
@@ -3364,6 +3393,8 @@ async function renderWithRestartOnCacheMissInDev(
33643393
await cacheSignal.cacheReady()
33653394
initialReactController.abort()
33663395

3396+
console.log('*********** restarting render ***********')
3397+
33673398
//===============================================
33683399
// Final render (restarted)
33693400
//===============================================
@@ -3411,6 +3442,7 @@ async function renderWithRestartOnCacheMissInDev(
34113442
const finalServerStream = await workUnitAsyncStorage.run(requestStore, () =>
34123443
pipelineInSequentialTasks(
34133444
() => {
3445+
console.log('=================== [final] Static ===================')
34143446
// Static stage
34153447
finalStageController.advanceStage(RenderStage.Static)
34163448

@@ -3437,11 +3469,23 @@ async function renderWithRestartOnCacheMissInDev(
34373469
return continuationStream
34383470
},
34393471
(stream) => {
3472+
if (finalStageController.currentStage !== RenderStage.Static) {
3473+
console.log(
3474+
`[app-render] stage was advanced to ${RenderStage[finalStageController.currentStage]} before reaching the runtime stage`
3475+
)
3476+
}
3477+
console.log('=================== [final] Runtime ===================')
34403478
// Runtime stage
34413479
finalStageController.advanceStage(RenderStage.Runtime)
34423480
return stream
34433481
},
34443482
(stream) => {
3483+
if (finalStageController.currentStage !== RenderStage.Runtime) {
3484+
console.log(
3485+
`[app-render] stage was advanced to ${RenderStage[finalStageController.currentStage]} before reaching the dynamic stage`
3486+
)
3487+
}
3488+
console.log('=================== [final] Dynamic ===================')
34453489
// Dynamic stage
34463490
finalStageController.advanceStage(RenderStage.Dynamic)
34473491
return stream
@@ -3650,6 +3694,32 @@ async function spawnStaticShellValidationInDev(
36503694
workStore,
36513695
} = ctx
36523696

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

36553725
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]/unwrapped/[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]/unwrapped/[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('/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]/unwrapped/[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]/unwrapped/[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)