Skip to content

Commit

Permalink
update vary header
Browse files Browse the repository at this point in the history
  • Loading branch information
snyamathi committed Jun 27, 2024
1 parent 8f21281 commit cb29878
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import {
RSC_CONTENT_TYPE_HEADER,
NEXT_ROUTER_STATE_TREE,
NEXT_DID_POSTPONE_HEADER,
NEXT_BUILD_ID_HEADER,
} from '../client/components/app-router-headers'
import { webpackBuild } from './webpack-build'
import { NextBuildContext, type MappedPages } from './build-context'
Expand Down Expand Up @@ -291,6 +292,7 @@ export type RoutesManifest = {
prefetchHeader: typeof NEXT_ROUTER_PREFETCH_HEADER
suffix: typeof RSC_SUFFIX
prefetchSuffix: typeof RSC_PREFETCH_SUFFIX
buildIdHeader: typeof NEXT_BUILD_ID_HEADER
}
skipMiddlewareUrlNormalize?: boolean
caseSensitive?: boolean
Expand Down Expand Up @@ -1172,12 +1174,13 @@ export default async function build(
header: RSC_HEADER,
// This vary header is used as a default. It is technically re-assigned in `base-server`,
// and may include an additional Vary option for `Next-URL`.
varyHeader: `${RSC_HEADER}, ${NEXT_ROUTER_STATE_TREE}, ${NEXT_ROUTER_PREFETCH_HEADER}`,
varyHeader: `${RSC_HEADER}, ${NEXT_ROUTER_STATE_TREE}, ${NEXT_ROUTER_PREFETCH_HEADER}, ${NEXT_BUILD_ID_HEADER}`,
prefetchHeader: NEXT_ROUTER_PREFETCH_HEADER,
didPostponeHeader: NEXT_DID_POSTPONE_HEADER,
contentTypeHeader: RSC_CONTENT_TYPE_HEADER,
suffix: RSC_SUFFIX,
prefetchSuffix: RSC_PREFETCH_SUFFIX,
buildIdHeader: NEXT_BUILD_ID_HEADER,
},
skipMiddlewareUrlNormalize: config.skipMiddlewareUrlNormalize,
} as RoutesManifest
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/client/components/app-router-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export const NEXT_ROUTER_STATE_TREE = 'Next-Router-State-Tree' as const
export const NEXT_ROUTER_PREFETCH_HEADER = 'Next-Router-Prefetch' as const
export const NEXT_URL = 'Next-Url' as const
export const RSC_CONTENT_TYPE_HEADER = 'text/x-component' as const
export const NEXT_BUILD_ID_HEADER = 'Next-Build-Id' as const

export const FLIGHT_PARAMETERS = [
[RSC_HEADER],
[NEXT_ROUTER_STATE_TREE],
[NEXT_ROUTER_PREFETCH_HEADER],
[NEXT_BUILD_ID_HEADER],
] as const

export const NEXT_RSC_UNION_QUERY = '_rsc' as const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
RSC_HEADER,
RSC_CONTENT_TYPE_HEADER,
NEXT_DID_POSTPONE_HEADER,
NEXT_BUILD_ID_HEADER,
} from '../app-router-headers'
import { urlToUrlWithoutFlightMarker } from '../app-router'
import { callServer } from '../../app-call-server'
Expand Down Expand Up @@ -56,13 +57,15 @@ export async function fetchServerResponse(
[NEXT_ROUTER_STATE_TREE]: string
[NEXT_URL]?: string
[NEXT_ROUTER_PREFETCH_HEADER]?: '1'
[NEXT_BUILD_ID_HEADER]: string
} = {
// Enable flight response
[RSC_HEADER]: '1',
// Provide the current router state
[NEXT_ROUTER_STATE_TREE]: encodeURIComponent(
JSON.stringify(flightRouterState)
),
[NEXT_BUILD_ID_HEADER]: currentBuildId,
}

/**
Expand All @@ -84,7 +87,7 @@ export async function fetchServerResponse(
headers[NEXT_ROUTER_PREFETCH_HEADER] || '0',
headers[NEXT_ROUTER_STATE_TREE],
headers[NEXT_URL],
currentBuildId,
headers[NEXT_BUILD_ID_HEADER],
].join(',')
)

Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
NEXT_DID_POSTPONE_HEADER,
NEXT_URL,
NEXT_ROUTER_STATE_TREE,
NEXT_BUILD_ID_HEADER,
} from '../client/components/app-router-headers'
import type {
MatchOptions,
Expand Down Expand Up @@ -1833,7 +1834,7 @@ export default abstract class Server<
isAppPath: boolean,
resolvedPathname: string
): void {
const baseVaryHeader = `${RSC_HEADER}, ${NEXT_ROUTER_STATE_TREE}, ${NEXT_ROUTER_PREFETCH_HEADER}`
const baseVaryHeader = `${RSC_HEADER}, ${NEXT_ROUTER_STATE_TREE}, ${NEXT_ROUTER_PREFETCH_HEADER}, ${NEXT_BUILD_ID_HEADER}`
const isRSCRequest = getRequestMeta(req, 'isRSCRequest') ?? false

let addedNextUrlToVary = false
Expand Down

0 comments on commit cb29878

Please sign in to comment.