Skip to content

Commit 7731039

Browse files
committed
Revert "[Segment Cache] Add "client-only" option (#77655)"
This reverts commit 713caf6.
1 parent f3eb893 commit 7731039

File tree

17 files changed

+18
-325
lines changed

17 files changed

+18
-325
lines changed

packages/next/src/client/components/segment-cache-impl/cache.ts

+12-58
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,6 @@ export async function fetchRouteOnCacheMiss(
10281028

10291029
writeDynamicTreeResponseIntoCache(
10301030
Date.now(),
1031-
task,
10321031
response,
10331032
serverData,
10341033
entry,
@@ -1247,10 +1246,6 @@ export async function fetchSegmentPrefetchesUsingDynamicRequest(
12471246
prefetchStream
12481247
) as Promise<NavigationFlightResponse>)
12491248

1250-
// Since we did not set the prefetch header, the response from the server
1251-
// will never contain dynamic holes.
1252-
const isResponsePartial = false
1253-
12541249
// Aside from writing the data into the cache, this function also returns
12551250
// the entries that were fulfilled, so we can streamingly update their sizes
12561251
// in the LRU as more data comes in.
@@ -1259,7 +1254,6 @@ export async function fetchSegmentPrefetchesUsingDynamicRequest(
12591254
task,
12601255
response,
12611256
serverData,
1262-
isResponsePartial,
12631257
route,
12641258
spawnedEntries
12651259
)
@@ -1275,7 +1269,6 @@ export async function fetchSegmentPrefetchesUsingDynamicRequest(
12751269

12761270
function writeDynamicTreeResponseIntoCache(
12771271
now: number,
1278-
task: PrefetchTask,
12791272
response: Response,
12801273
serverData: NavigationFlightResponse,
12811274
entry: PendingRouteCacheEntry,
@@ -1318,43 +1311,16 @@ function writeDynamicTreeResponseIntoCache(
13181311
staleTimeHeaderSeconds !== null
13191312
? parseInt(staleTimeHeaderSeconds, 10) * 1000
13201313
: STATIC_STALETIME_MS
1321-
1322-
// If the response contains dynamic holes, then we must conservatively assume
1323-
// that any individual segment might contain dynamic holes, and also the
1324-
// head. If it did not contain dynamic holes, then we can assume every segment
1325-
// and the head is completely static.
1326-
const isResponsePartial =
1327-
response.headers.get(NEXT_DID_POSTPONE_HEADER) === '1'
1328-
1329-
const fulfilledEntry = fulfillRouteCacheEntry(
1314+
fulfillRouteCacheEntry(
13301315
entry,
13311316
convertRootFlightRouterStateToRouteTree(flightRouterState),
13321317
flightData.head,
1333-
isResponsePartial,
1318+
flightData.isHeadPartial,
13341319
now + staleTimeMs,
13351320
couldBeIntercepted,
13361321
canonicalUrl,
13371322
routeIsPPREnabled
13381323
)
1339-
1340-
// If the server sent segment data as part of the response, we should write
1341-
// it into the cache to prevent a second, redundant prefetch request.
1342-
//
1343-
// TODO: When `clientSegmentCache` is enabled, the server does not include
1344-
// segment data when responding to a route tree prefetch request. However,
1345-
// when `clientSegmentCache` is set to "client-only", and PPR is enabled (or
1346-
// the page is fully static), the normal check is bypassed and the server
1347-
// responds with the full page. This is a temporary situation until we can
1348-
// remove the "client-only" option. Then, we can delete this function call.
1349-
writeDynamicRenderResponseIntoCache(
1350-
now,
1351-
task,
1352-
response,
1353-
serverData,
1354-
isResponsePartial,
1355-
fulfilledEntry,
1356-
null
1357-
)
13581324
}
13591325

13601326
function rejectSegmentEntriesIfStillPending(
@@ -1377,19 +1343,16 @@ function writeDynamicRenderResponseIntoCache(
13771343
task: PrefetchTask,
13781344
response: Response,
13791345
serverData: NavigationFlightResponse,
1380-
isResponsePartial: boolean,
13811346
route: FulfilledRouteCacheEntry,
1382-
spawnedEntries: Map<string, PendingSegmentCacheEntry> | null
1347+
spawnedEntries: Map<string, PendingSegmentCacheEntry>
13831348
): Array<FulfilledSegmentCacheEntry> | null {
13841349
if (serverData.b !== getAppBuildId()) {
13851350
// The server build does not match the client. Treat as a 404. During
13861351
// an actual navigation, the router will trigger an MPA navigation.
13871352
// TODO: Consider moving the build ID to a response header so we can check
13881353
// it before decoding the response, and so there's one way of checking
13891354
// across all response types.
1390-
if (spawnedEntries !== null) {
1391-
rejectSegmentEntriesIfStillPending(spawnedEntries, now + 10 * 1000)
1392-
}
1355+
rejectSegmentEntriesIfStillPending(spawnedEntries, now + 10 * 1000)
13931356
return null
13941357
}
13951358
const flightDatas = normalizeFlightData(serverData.f)
@@ -1432,7 +1395,6 @@ function writeDynamicRenderResponseIntoCache(
14321395
route,
14331396
now + staleTimeMs,
14341397
seedData,
1435-
isResponsePartial,
14361398
segmentKey,
14371399
spawnedEntries
14381400
)
@@ -1446,14 +1408,11 @@ function writeDynamicRenderResponseIntoCache(
14461408
// segments we're marking as rejected here. We should mark on the segment
14471409
// somehow that the reason for the rejection is because of a non-PPR prefetch.
14481410
// That way a per-segment prefetch knows to disregard the rejection.
1449-
if (spawnedEntries !== null) {
1450-
const fulfilledEntries = rejectSegmentEntriesIfStillPending(
1451-
spawnedEntries,
1452-
now + 10 * 1000
1453-
)
1454-
return fulfilledEntries
1455-
}
1456-
return null
1411+
const fulfilledEntries = rejectSegmentEntriesIfStillPending(
1412+
spawnedEntries,
1413+
now + 10 * 1000
1414+
)
1415+
return fulfilledEntries
14571416
}
14581417

14591418
function writeSeedDataIntoCache(
@@ -1462,9 +1421,8 @@ function writeSeedDataIntoCache(
14621421
route: FulfilledRouteCacheEntry,
14631422
staleAt: number,
14641423
seedData: CacheNodeSeedData,
1465-
isResponsePartial: boolean,
14661424
key: string,
1467-
entriesOwnedByCurrentTask: Map<string, PendingSegmentCacheEntry> | null
1425+
entriesOwnedByCurrentTask: Map<string, PendingSegmentCacheEntry>
14681426
) {
14691427
// This function is used to write the result of a dynamic server request
14701428
// (CacheNodeSeedData) into the prefetch cache. It's used in cases where we
@@ -1473,15 +1431,12 @@ function writeSeedDataIntoCache(
14731431
// dynamic data into being static) and when prefetching a PPR-disabled route
14741432
const rsc = seedData[1]
14751433
const loading = seedData[3]
1476-
const isPartial = rsc === null || isResponsePartial
1434+
const isPartial = rsc === null
14771435

14781436
// We should only write into cache entries that are owned by us. Or create
14791437
// a new one and write into that. We must never write over an entry that was
14801438
// created by a different task, because that causes data races.
1481-
const ownedEntry =
1482-
entriesOwnedByCurrentTask !== null
1483-
? entriesOwnedByCurrentTask.get(key)
1484-
: undefined
1439+
const ownedEntry = entriesOwnedByCurrentTask.get(key)
14851440
if (ownedEntry !== undefined) {
14861441
fulfillSegmentCacheEntry(ownedEntry, rsc, loading, staleAt, isPartial)
14871442
} else {
@@ -1526,7 +1481,6 @@ function writeSeedDataIntoCache(
15261481
route,
15271482
staleAt,
15281483
childSeedData,
1529-
isResponsePartial,
15301484
encodeChildSegmentKey(
15311485
key,
15321486
parallelRouteKey,

packages/next/src/export/index.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,7 @@ async function exportAppImpl(
391391
clientTraceMetadata: nextConfig.experimental.clientTraceMetadata,
392392
expireTime: nextConfig.expireTime,
393393
dynamicIO: nextConfig.experimental.dynamicIO ?? false,
394-
clientSegmentCache:
395-
nextConfig.experimental.clientSegmentCache === 'client-only'
396-
? 'client-only'
397-
: Boolean(nextConfig.experimental.clientSegmentCache),
394+
clientSegmentCache: nextConfig.experimental.clientSegmentCache ?? false,
398395
inlineCss: nextConfig.experimental.inlineCss ?? false,
399396
authInterrupts: !!nextConfig.experimental.authInterrupts,
400397
},

packages/next/src/server/app-render/app-render.tsx

+1-11
Original file line numberDiff line numberDiff line change
@@ -4220,17 +4220,7 @@ async function collectSegmentData(
42204220
// decomposed into a separate stream per segment.
42214221

42224222
const clientReferenceManifest = renderOpts.clientReferenceManifest
4223-
if (
4224-
!clientReferenceManifest ||
4225-
// Do not generate per-segment data unless the experimental Segment Cache
4226-
// flag is enabled.
4227-
//
4228-
// We also skip generating segment data if flag is set to "client-only",
4229-
// rather than true. (The "client-only" option only affects the behavior of
4230-
// the client-side implementation; per-segment prefetches are intentionally
4231-
// disabled in that configuration).
4232-
renderOpts.experimental.clientSegmentCache !== true
4233-
) {
4223+
if (!clientReferenceManifest || !renderOpts.experimental.clientSegmentCache) {
42344224
return
42354225
}
42364226

packages/next/src/server/app-render/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export interface RenderOptsPartial {
213213
expireTime: number | undefined
214214
clientTraceMetadata: string[] | undefined
215215
dynamicIO: boolean
216-
clientSegmentCache: boolean | 'client-only'
216+
clientSegmentCache: boolean
217217
inlineCss: boolean
218218
authInterrupts: boolean
219219
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,7 @@ export default abstract class Server<
605605
clientTraceMetadata: this.nextConfig.experimental.clientTraceMetadata,
606606
dynamicIO: this.nextConfig.experimental.dynamicIO ?? false,
607607
clientSegmentCache:
608-
this.nextConfig.experimental.clientSegmentCache === 'client-only'
609-
? 'client-only'
610-
: Boolean(this.nextConfig.experimental.clientSegmentCache),
608+
this.nextConfig.experimental.clientSegmentCache ?? false,
611609
inlineCss: this.nextConfig.experimental.inlineCss ?? false,
612610
authInterrupts: !!this.nextConfig.experimental.authInterrupts,
613611
},

packages/next/src/server/config-schema.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
299299
memoryBasedWorkersCount: z.boolean().optional(),
300300
craCompat: z.boolean().optional(),
301301
caseSensitiveRoutes: z.boolean().optional(),
302-
clientSegmentCache: z
303-
.union([z.boolean(), z.literal('client-only')])
304-
.optional(),
302+
clientSegmentCache: z.boolean().optional(),
305303
disableOptimizedLoading: z.boolean().optional(),
306304
disablePostcssPresetEnv: z.boolean().optional(),
307305
dynamicIO: z.boolean().optional(),

packages/next/src/server/config-shared.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export interface ExperimentalConfig {
269269
prerenderEarlyExit?: boolean
270270
linkNoTouchStart?: boolean
271271
caseSensitiveRoutes?: boolean
272-
clientSegmentCache?: boolean | 'client-only'
272+
clientSegmentCache?: boolean
273273
appDocumentPreloading?: boolean
274274
preloadEntriesOnStart?: boolean
275275
/** @default true */

test/e2e/app-dir/segment-cache/client-only-opt-in/app/dynamic-with-ppr/loading.tsx

-3
This file was deleted.

test/e2e/app-dir/segment-cache/client-only-opt-in/app/dynamic-with-ppr/page.tsx

-8
This file was deleted.

test/e2e/app-dir/segment-cache/client-only-opt-in/app/dynamic-without-ppr/loading.tsx

-3
This file was deleted.

test/e2e/app-dir/segment-cache/client-only-opt-in/app/dynamic-without-ppr/page.tsx

-6
This file was deleted.

test/e2e/app-dir/segment-cache/client-only-opt-in/app/layout.tsx

-11
This file was deleted.

test/e2e/app-dir/segment-cache/client-only-opt-in/app/page.tsx

-35
This file was deleted.

test/e2e/app-dir/segment-cache/client-only-opt-in/app/static/page.tsx

-3
This file was deleted.

0 commit comments

Comments
 (0)