mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This fixes some of headers (and adds associated tests) for pages when
PPR is enabled. Namely, the `Cache-Control` headers are now returning
correctly, reflecting the non-cachability of some requests:
- Requests that postpone (dynamic data is streamed after the initial
static shell is streamed)
- Requests for the Dynamic RSC payload
Additionally, the `X-NextJS-Cache` header has been updated for better
support for PPR:
- Requests that postpone no longer return this header as it doesn't
reflect the cache state of the request (because it streams)
- Requests for the Prefetch RSC now returns the correct cache headers
depending on the segment and pre-postpone state
This also enables the other pathnames in the test suites 🙌🏻
Closes NEXT-1840
39 lines
914 B
React
39 lines
914 B
React
import React, { use } from 'react'
|
|
import * as next from 'next/headers'
|
|
|
|
export const Dynamic = ({ pathname, fallback }) => {
|
|
if (fallback) {
|
|
return <div>Dynamic Loading...</div>
|
|
}
|
|
|
|
const headers = next.headers()
|
|
const messages = []
|
|
for (const name of ['x-test-input', 'user-agent']) {
|
|
messages.push({ name, value: headers.get(name) })
|
|
}
|
|
|
|
const delay = headers.get('x-delay')
|
|
if (delay) {
|
|
use(new Promise((resolve) => setTimeout(resolve, parseInt(delay, 10))))
|
|
}
|
|
|
|
return (
|
|
<dl>
|
|
{pathname && (
|
|
<>
|
|
<dt>Pathname</dt>
|
|
<dd data-pathname={pathname}>{pathname}</dd>
|
|
</>
|
|
)}
|
|
{messages.map(({ name, value }) => (
|
|
<React.Fragment key={name}>
|
|
<dt>
|
|
Header: <code>{name}</code>
|
|
</dt>
|
|
<dd>{value ?? `MISSING:${name.toUpperCase()}`}</dd>
|
|
</React.Fragment>
|
|
))}
|
|
</dl>
|
|
)
|
|
}
|