Skip to content

Commit a15b974

Browse files
authored
[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.
1 parent 69afa37 commit a15b974

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

packages/next/src/server/base-server.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,7 +3054,11 @@ export default abstract class Server<
30543054
}
30553055
)
30563056

3057-
if (isPrefetchRSCRequest && typeof segmentPrefetchHeader === 'string') {
3057+
if (
3058+
isRoutePPREnabled &&
3059+
isPrefetchRSCRequest &&
3060+
typeof segmentPrefetchHeader === 'string'
3061+
) {
30583062
// This is a prefetch request issued by the client Segment Cache. These
30593063
// should never reach the application layer (lambda). We should either
30603064
// respond from the cache (HIT) or respond with 204 No Content (MISS).
@@ -3090,15 +3094,14 @@ export default abstract class Server<
30903094
// segment), we should *always* respond with a tree, even if PPR
30913095
// is disabled.
30923096
res.statusCode = 204
3093-
if (isRoutePPREnabled) {
3094-
// Set a header to indicate that PPR is enabled for this route. This
3095-
// lets the client distinguish between a regular cache miss and a cache
3096-
// miss due to PPR being disabled.
3097-
// NOTE: Theoretically, when PPR is enabled, there should *never* be
3098-
// a cache miss because we should generate a fallback route. So this
3099-
// is mostly defensive.
3100-
res.setHeader(NEXT_DID_POSTPONE_HEADER, '1')
3101-
}
3097+
3098+
// Set a header to indicate that PPR is enabled for this route. This
3099+
// lets the client distinguish between a regular cache miss and a cache
3100+
// miss due to PPR being disabled.
3101+
// NOTE: Theoretically, when PPR is enabled, there should *never* be
3102+
// a cache miss because we should generate a fallback route. So this
3103+
// is mostly defensive.
3104+
res.setHeader(NEXT_DID_POSTPONE_HEADER, '1')
31023105
return {
31033106
type: 'rsc',
31043107
body: RenderResult.fromStatic(''),

test/e2e/app-dir/segment-cache/incremental-opt-in/segment-cache-incremental-opt-in.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { nextTestSetup } from 'e2e-utils'
22

3-
describe('segment cache (incremental opt in)', () => {
3+
// Backport Note: This test is skipped as it's only currently usable in the experimental release channel.
4+
describe.skip('segment cache (incremental opt in)', () => {
45
const { next, isNextDev, skipped } = nextTestSetup({
56
files: __dirname,
67
skipDeployment: true,

test/e2e/pages-performance-mark/pages/_document.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Html, Head, Main, NextScript } from 'next/document'
33
export default function Document() {
44
return (
55
<Html>
6-
<Head />
76
<Head />
87
<body>
98
<Main />

0 commit comments

Comments
 (0)