Unverified Commit a15b974e authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

[backport]: properly gate segmentCache branch in base-server (#79505)

In 15.1, this branch should be a no-op when PPR is not enabled, because
`collectSegmentData` is
[gated](https://github.com/vercel/next.js/blob/69afa37323610c9bbfbecd22f0194f2f299d5a6c/packages/next/src/server/app-render/app-render.tsx#L4008)
on `isRoutePPREnabled`.

This also sets a no-store cache header when we respond with a 204 to
align with intended behavior.
parent 69afa373
......@@ -3054,7 +3054,11 @@ export default abstract class Server<
}
)
if (isPrefetchRSCRequest && typeof segmentPrefetchHeader === 'string') {
if (
isRoutePPREnabled &&
isPrefetchRSCRequest &&
typeof segmentPrefetchHeader === 'string'
) {
// This is a prefetch request issued by the client Segment Cache. These
// should never reach the application layer (lambda). We should either
// respond from the cache (HIT) or respond with 204 No Content (MISS).
......@@ -3090,15 +3094,14 @@ export default abstract class Server<
// segment), we should *always* respond with a tree, even if PPR
// is disabled.
res.statusCode = 204
if (isRoutePPREnabled) {
// Set a header to indicate that PPR is enabled for this route. This
// lets the client distinguish between a regular cache miss and a cache
// miss due to PPR being disabled.
// NOTE: Theoretically, when PPR is enabled, there should *never* be
// a cache miss because we should generate a fallback route. So this
// is mostly defensive.
res.setHeader(NEXT_DID_POSTPONE_HEADER, '1')
}
// Set a header to indicate that PPR is enabled for this route. This
// lets the client distinguish between a regular cache miss and a cache
// miss due to PPR being disabled.
// NOTE: Theoretically, when PPR is enabled, there should *never* be
// a cache miss because we should generate a fallback route. So this
// is mostly defensive.
res.setHeader(NEXT_DID_POSTPONE_HEADER, '1')
return {
type: 'rsc',
body: RenderResult.fromStatic(''),
......
import { nextTestSetup } from 'e2e-utils'
describe('segment cache (incremental opt in)', () => {
// Backport Note: This test is skipped as it's only currently usable in the experimental release channel.
describe.skip('segment cache (incremental opt in)', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
......
......@@ -3,7 +3,6 @@ import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html>
<Head />
<Head />
<body>
<Main />
......
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