Unverified Commit b1f49163 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Return APP_PAGE instead of PAGES for production Instant Navigation tests (#95184)

### Why?

Current behavior:
https://github.com/vercel/next.js/actions/runs/28225010081/job/83615571987?pr=95184#step:31:8732

For a minimal-mode resume request carrying the Instant Navigation
testing cookie, Next.js skips the postponed render so the test receives
only the prefetched static shell. The resulting empty continuation was
represented as `PAGES`, but the App Page handler requires `APP_PAGE`,
causing error:

```
Error: Invariant app-page handler received invalid cache entry PAGES
```

### How?

Return an empty `APP_PAGE` response with the correct HTML or RSC content
type and postponed metadata. If the document continuation has no
`<head>` chunk, insert the Instant Navigation bootstrap while flushing
the stream.

Add production regression coverage for document and RSC-prefetch resume
requests using build-generated postponed state.

<!-- NEXT_JS_LLM_PR -->
parent 287c04cf
...@@ -62,7 +62,6 @@ import { ...@@ -62,7 +62,6 @@ import {
CachedRouteKind, CachedRouteKind,
IncrementalCacheKind, IncrementalCacheKind,
type CachedAppPageValue, type CachedAppPageValue,
type CachedPageValue,
type ResponseCacheEntry, type ResponseCacheEntry,
type ResponseGenerator, type ResponseGenerator,
} from '../../server/response-cache' with { 'turbopack-transition': 'next-server-utility' } } from '../../server/response-cache' with { 'turbopack-transition': 'next-server-utility' }
...@@ -1410,7 +1409,8 @@ export async function handler( ...@@ -1410,7 +1409,8 @@ export async function handler(
} }
// When we're in minimal mode, if we're trying to debug the static shell, // When we're in minimal mode, if we're trying to debug the static shell,
// we should just return nothing instead of resuming the dynamic render. // return an empty App Page response instead of resuming the dynamic
// render. The static shell has already been streamed by the platform.
if ( if (
(isDebugStaticShell || isDebugDynamicAccesses) && (isDebugStaticShell || isDebugDynamicAccesses) &&
typeof postponed !== 'undefined' typeof postponed !== 'undefined'
...@@ -1418,12 +1418,19 @@ export async function handler( ...@@ -1418,12 +1418,19 @@ export async function handler(
return { return {
cacheControl: { revalidate: 1, expire: undefined }, cacheControl: { revalidate: 1, expire: undefined },
value: { value: {
kind: CachedRouteKind.PAGES, kind: CachedRouteKind.APP_PAGE,
html: RenderResult.EMPTY, html: RenderResult.fromStatic(
pageData: {}, '',
isRSCRequest
? RSC_CONTENT_TYPE_HEADER
: HTML_CONTENT_TYPE_HEADER
),
rscData: undefined,
postponed,
segmentData: undefined,
headers: undefined, headers: undefined,
status: undefined, status: undefined,
} satisfies CachedPageValue, } satisfies CachedAppPageValue,
} }
} }
......
import type { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { Suspense } from 'react'
import { connection } from 'next/server'
async function DynamicContent() {
await connection()
return <p id="dynamic">dynamic content</p>
}
export default function Page() {
return (
<main>
<p id="shell">static shell</p>
<Suspense fallback={<p id="fallback">loading</p>}>
<DynamicContent />
</Suspense>
</main>
)
}
import { nextTestSetup } from 'e2e-utils'
describe('instant-navigation-resume', () => {
const { next } = nextTestSetup({
files: __dirname,
// This test directly emulates the platform's internal resume request using
// locally generated postponed state and private runtime switches.
skipDeployment: true,
env: {
NEXT_PRIVATE_TEST_HEADERS: '1',
NEXT_PRIVATE_MINIMAL_MODE: '1',
},
})
async function getPostponedState() {
const { postponed } = await next.readJSON('.next/server/app/index.meta')
expect(postponed).toEqual(expect.any(String))
expect(postponed.length).toBeGreaterThan(0)
return postponed as string
}
it('handles an instant-navigation document resume', async () => {
const postponed = await getPostponedState()
const cliOutputIndex = next.cliOutput.length
const response = await next.fetch('/', {
method: 'POST',
headers: {
cookie: 'next-instant-navigation-testing=1',
'next-resume': '1',
'x-matched-path': '/',
},
body: postponed,
})
expect(response.status).toBe(200)
await response.text()
expect(
next.cliOutput
.slice(cliOutputIndex)
.match(/Invariant app-page handler received invalid cache entry PAGES/)
).toBeNull()
})
it('handles an instant-navigation RSC prefetch resume', async () => {
const postponed = await getPostponedState()
const cliOutputIndex = next.cliOutput.length
const response = await next.fetch('/', {
method: 'POST',
headers: {
cookie: 'next-instant-navigation-testing=1',
'next-resume': '1',
'next-router-prefetch': '1',
rsc: '1',
'x-matched-path': '/',
},
body: postponed,
})
expect(response.status).toBe(200)
await response.text()
expect(
next.cliOutput
.slice(cliOutputIndex)
.match(/Invariant app-page handler received invalid cache entry PAGES/)
).toBeNull()
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
cacheComponents: true,
experimental: {
exposeTestingApiInProductionBuild: true,
},
}
module.exports = nextConfig
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