Unverified Commit dc41d9c6 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add param to debug PPR skeleton in dev (#62703)

This adds an experimental query `__nextppronly` to allow debugging PPR
skeletons in development to avoid having to do numerous builds to be
able to debug this experience.

x-ref: [slack
thread](https://vercel.slack.com/archives/C05KYT5S9FF/p1709151588583179?thread_ts=1708474869.960689&cid=C05KYT5S9FF)
parent 7d8a923f
...@@ -150,6 +150,7 @@ export interface RenderOptsPartial { ...@@ -150,6 +150,7 @@ export interface RenderOptsPartial {
swrDelta: SwrDelta | undefined swrDelta: SwrDelta | undefined
} }
postponed?: string postponed?: string
isStaticGeneration?: boolean
} }
export type RenderOpts = LoadComponentsReturnType<AppPageModule> & export type RenderOpts = LoadComponentsReturnType<AppPageModule> &
......
...@@ -2123,9 +2123,17 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2123,9 +2123,17 @@ export default abstract class Server<ServerOptions extends Options = Options> {
postponed: string | undefined postponed: string | undefined
}) => Promise<ResponseCacheEntry | null> }) => Promise<ResponseCacheEntry | null>
// allow debugging the skeleton in dev with PPR
// instead of continuing to resume stream right away
const debugPPRSkeleton = Boolean(
this.nextConfig.experimental.ppr &&
this.renderOpts.dev &&
query.__nextppronly
)
const doRender: Renderer = async ({ postponed }) => { const doRender: Renderer = async ({ postponed }) => {
// In development, we always want to generate dynamic HTML. // In development, we always want to generate dynamic HTML.
const supportsDynamicHTML: boolean = let supportsDynamicHTML: boolean =
// If this isn't a data request and we're not in development, then we // If this isn't a data request and we're not in development, then we
// support dynamic HTML. // support dynamic HTML.
(!isDataReq && opts.dev === true) || (!isDataReq && opts.dev === true) ||
...@@ -2197,6 +2205,14 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2197,6 +2205,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
postponed, postponed,
} }
if (debugPPRSkeleton) {
supportsDynamicHTML = false
renderOpts.nextExport = true
renderOpts.supportsDynamicHTML = false
renderOpts.isStaticGeneration = true
renderOpts.isRevalidate = true
}
// Legacy render methods will return a render result that needs to be // Legacy render methods will return a render result that needs to be
// served by the server. // served by the server.
let result: RenderResult let result: RenderResult
...@@ -2855,6 +2871,14 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2855,6 +2871,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
} }
} }
if (debugPPRSkeleton) {
return {
type: 'html',
body,
revalidate: 0,
}
}
// This request has postponed, so let's create a new transformer that the // This request has postponed, so let's create a new transformer that the
// dynamic data can pipe to that will attach the dynamic data to the end // dynamic data can pipe to that will attach the dynamic data to the end
// of the response. // of the response.
......
import { cookies } from 'next/headers'
import { Suspense } from 'react'
async function Suspend() {
await new Promise((resolve) => {
setTimeout(resolve, 3000)
})
cookies()
return <p>suspended content</p>
}
export default function Page() {
return (
<div>
<Suspense fallback={'Skeleton!!!'}>
<Suspend />
</Suspense>
</div>
)
}
...@@ -20,6 +20,17 @@ createNextDescribe( ...@@ -20,6 +20,17 @@ createNextDescribe(
}, },
}, },
({ next, isNextDev: isDev, isNextStart, isNextDeploy, isTurbopack }) => { ({ next, isNextDev: isDev, isNextStart, isNextDeploy, isTurbopack }) => {
if (isDev && isPPREnabledByDefault) {
it('should allow returning just skeleton in dev with query', async () => {
const res = await next.fetch('/skeleton?__nextppronly=1')
expect(res.status).toBe(200)
const html = await res.text()
expect(html).toContain('Skeleton')
expect(html).not.toContain('suspended content')
})
}
if (process.env.NEXT_EXPERIMENTAL_COMPILE) { if (process.env.NEXT_EXPERIMENTAL_COMPILE) {
it('should provide query for getStaticProps page correctly', async () => { it('should provide query for getStaticProps page correctly', async () => {
const res = await next.fetch('/ssg?hello=world') const res = await next.fetch('/ssg?hello=world')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment