Skip to content

Commit ac777e2

Browse files
authored
Remove redundant instant navigation prefetch header (#93713)
`NEXT_INSTANT_PREFETCH_HEADER` was replaced by `NEXT_INSTANT_TEST_COOKIE` in #89871. Deleting the dead code. <!-- NEXT_JS_LLM_PR -->
1 parent b480424 commit ac777e2

5 files changed

Lines changed: 19 additions & 50 deletions

File tree

packages/next/src/build/templates/app-page.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import {
4848
RSC_HEADER,
4949
NEXT_ROUTER_PREFETCH_HEADER,
5050
NEXT_ROUTER_SEGMENT_PREFETCH_HEADER,
51-
NEXT_INSTANT_PREFETCH_HEADER,
5251
NEXT_INSTANT_TEST_COOKIE,
5352
NEXT_IS_PRERENDER_HEADER,
5453
NEXT_DID_POSTPONE_HEADER,
@@ -420,17 +419,20 @@ export async function handler(
420419
// Enable the Instant Navigation Testing API. Renders only the prefetched
421420
// portion of the page, excluding dynamic content. This allows tests to
422421
// assert on the prefetched UI state deterministically.
423-
// - Header: Used for client-side navigations where we can set request headers
424-
// - Cookie: Used for MPA navigations (page reload, full page load) where we
425-
// can't set request headers. Only applies to document requests (no RSC
426-
// header) - RSC requests should proceed normally even during a locked scope,
427-
// with blocking happening on the client side.
422+
//
423+
// The instant test cookie is sent automatically with all requests while a
424+
// navigation lock is held. We treat a request as a test render when the
425+
// cookie is present and either:
426+
// - it's a document request (no RSC header) — covers MPA navigations
427+
// - it's a prefetch RSC request — covers client-side prefetches
428+
// Regular RSC navigation requests proceed normally even during a locked
429+
// scope; blocking happens on the client side.
428430
const isInstantNavigationTest =
429431
exposeTestingApi &&
430-
(req.headers[NEXT_INSTANT_PREFETCH_HEADER] === '1' ||
431-
(!isRSCRequestHeader(req.headers[RSC_HEADER]) &&
432-
typeof req.headers.cookie === 'string' &&
433-
req.headers.cookie.includes(NEXT_INSTANT_TEST_COOKIE + '=')))
432+
typeof req.headers.cookie === 'string' &&
433+
req.headers.cookie.includes(NEXT_INSTANT_TEST_COOKIE + '=') &&
434+
(!isRSCRequestHeader(req.headers[RSC_HEADER]) ||
435+
req.headers[NEXT_ROUTER_PREFETCH_HEADER] === '1')
434436

435437
// This page supports PPR if it is marked as being `PARTIALLY_STATIC` in the
436438
// prerender manifest and this is an app page.

packages/next/src/client/components/app-router-headers.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,9 @@ export const NEXT_HMR_REFRESH_HASH_COOKIE = '__next_hmr_refresh_hash__' as const
1616
export const NEXT_URL = 'next-url' as const
1717
export const RSC_CONTENT_TYPE_HEADER = 'text/x-component' as const
1818

19-
// Header for the Instant Navigation Testing API. In development and testing
20-
// builds, static pre-renders normally don't happen. This header tells the
21-
// server to perform a static pre-render anyway, allowing tests to assert on
22-
// the prefetched UI. Not exposed in production builds by default.
23-
export const NEXT_INSTANT_PREFETCH_HEADER =
24-
'next-instant-navigation-testing-prefetch' as const
25-
26-
// Cookie for the Instant Navigation Testing API. Used for MPA navigations
27-
// (page reload, full page load) where we can't set request headers. When set,
28-
// the server renders only the static shell. Not exposed in production builds
29-
// by default.
19+
// Cookie for the Instant Navigation Testing API. Sent automatically with all
20+
// requests while a navigation lock is held; the server uses its presence to
21+
// render only the static shell. Not exposed in production builds by default.
3022
export const NEXT_INSTANT_TEST_COOKIE =
3123
'next-instant-navigation-testing' as const
3224

packages/next/src/client/components/router-reducer/fetch-server-response.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type {
1818
import {
1919
type NEXT_ROUTER_PREFETCH_HEADER,
2020
type NEXT_ROUTER_SEGMENT_PREFETCH_HEADER,
21-
type NEXT_INSTANT_PREFETCH_HEADER,
2221
NEXT_ROUTER_STATE_TREE_HEADER,
2322
NEXT_RSC_UNION_QUERY,
2423
NEXT_URL,
@@ -110,7 +109,6 @@ export type RequestHeaders = {
110109
'Next-Test-Fetch-Priority'?: RequestInit['priority']
111110
[NEXT_HTML_REQUEST_ID_HEADER]?: string // dev-only
112111
[NEXT_REQUEST_ID_HEADER]?: string // dev-only
113-
[NEXT_INSTANT_PREFETCH_HEADER]?: '1' // testing API only
114112
}
115113

116114
function doMpaNavigation(url: string): FetchServerResponseResult {

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
} from '../../../shared/lib/segment-cache/vary-params-decoding'
1717
import {
1818
NEXT_DID_POSTPONE_HEADER,
19-
NEXT_INSTANT_PREFETCH_HEADER,
2019
NEXT_ROUTER_PREFETCH_HEADER,
2120
NEXT_ROUTER_SEGMENT_PREFETCH_HEADER,
2221
NEXT_ROUTER_STALE_TIME_HEADER,
@@ -1598,9 +1597,6 @@ export async function fetchRouteOnCacheMiss(
15981597
if (nextUrl !== null) {
15991598
headers[NEXT_URL] = nextUrl
16001599
}
1601-
// Tell the server to perform a static pre-render for the Instant Navigation
1602-
// Testing API. Static pre-renders don't normally happen during development.
1603-
addInstantPrefetchHeaderIfLocked(headers)
16041600

16051601
try {
16061602
const url = new URL(pathname + search, location.origin)
@@ -1930,9 +1926,6 @@ export async function fetchSegmentsOnCacheMiss(
19301926
if (nextUrl !== null) {
19311927
headers[NEXT_URL] = nextUrl
19321928
}
1933-
// Tell the server to perform a static pre-render for the Instant Navigation
1934-
// Testing API. Static pre-renders don't normally happen during development.
1935-
addInstantPrefetchHeaderIfLocked(headers)
19361929

19371930
const requestUrl = isOutputExportMode
19381931
? // In output: "export" mode, we need to add the segment path to the URL.
@@ -2871,22 +2864,6 @@ export function canNewFetchStrategyProvideMoreContent(
28712864
return currentStrategy < newStrategy
28722865
}
28732866

2874-
/**
2875-
* Adds the instant prefetch header if the navigation lock is active.
2876-
* Uses a lazy require to ensure dead code elimination.
2877-
*/
2878-
function addInstantPrefetchHeaderIfLocked(
2879-
headers: Record<string, string>
2880-
): void {
2881-
if (process.env.__NEXT_EXPOSE_TESTING_API) {
2882-
const { isNavigationLocked } =
2883-
require('./navigation-testing-lock') as typeof import('./navigation-testing-lock')
2884-
if (isNavigationLocked()) {
2885-
headers[NEXT_INSTANT_PREFETCH_HEADER] = '1'
2886-
}
2887-
}
2888-
}
2889-
28902867
function getStaleAtFromHeader(
28912868
now: number,
28922869
response: RSCResponse<unknown>

packages/next/src/server/stream-utils/node-web-streams-helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
NEXT_ROUTER_PREFETCH_HEADER,
2020
NEXT_ROUTER_SEGMENT_PREFETCH_HEADER,
2121
NEXT_RSC_UNION_QUERY,
22-
NEXT_INSTANT_PREFETCH_HEADER,
2322
} from '../../client/components/app-router-headers'
2423
import { computeCacheBustingSearchParam } from '../../shared/lib/router/utils/cache-busting-search-param'
2524
import type { AnyStream } from '../app-render/stream-ops'
@@ -590,8 +589,9 @@ export async function createInstantTestScriptInsertionTransformStream(
590589
): Promise<TransformStream<Uint8Array, Uint8Array>> {
591590
// Kick off a fetch for the static RSC payload. This is the hydration
592591
// source for the locked static shell — same as the __NEXT_CLIENT_RESUME
593-
// fetch used for fallback routes, but with NEXT_INSTANT_PREFETCH_HEADER
594-
// so the server returns static-only data.
592+
// fetch used for fallback routes. The instant test cookie is sent
593+
// automatically with the same-origin fetch, so the server returns
594+
// static-only data.
595595
//
596596
// The fetch promise is stored as self.__next_instant_test, which doubles
597597
// as the feature flag (truthy = instant test mode). The client processes
@@ -610,7 +610,7 @@ export async function createInstantTestScriptInsertionTransformStream(
610610
// bootstrapScriptContent.
611611
const requestIdScript =
612612
requestId !== null ? `self.__next_r=${JSON.stringify(requestId)};` : ''
613-
const INSTANT_TEST_SCRIPT = `<script>${requestIdScript}self.__next_instant_test=fetch(location.pathname+'?${searchStr}',{credentials:'same-origin',headers:{'${RSC_HEADER}':'1','${NEXT_ROUTER_PREFETCH_HEADER}':'1','${NEXT_ROUTER_SEGMENT_PREFETCH_HEADER}':'${segmentPath}','${NEXT_INSTANT_PREFETCH_HEADER}':'1'}})</script>`
613+
const INSTANT_TEST_SCRIPT = `<script>${requestIdScript}self.__next_instant_test=fetch(location.pathname+'?${searchStr}',{credentials:'same-origin',headers:{'${RSC_HEADER}':'1','${NEXT_ROUTER_PREFETCH_HEADER}':'1','${NEXT_ROUTER_SEGMENT_PREFETCH_HEADER}':'${segmentPath}'}})</script>`
614614

615615
let didAlreadyInsert = false
616616
return new TransformStream({

0 commit comments

Comments
 (0)