Skip to content

Commit

Permalink
Rename flight parameters to rsc/next (vercel#40979)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and BowlingX committed Oct 5, 2022
1 parent 619284a commit 3a4db8a
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions packages/next/client/components/app-router.client.tsx
Expand Up @@ -44,18 +44,18 @@ export async function fetchServerResponse(
prefetch?: true
): Promise<[FlightData: FlightData, canonicalUrlOverride: URL | undefined]> {
const headers: {
__flight__: '1'
__flight_router_state_tree__: string
__flight_prefetch__?: '1'
__rsc__: '1'
__next_router_state_tree__: string
__next_router_prefetch__?: '1'
} = {
// Enable flight response
__flight__: '1',
__rsc__: '1',
// Provide the current router state
__flight_router_state_tree__: JSON.stringify(flightRouterState),
__next_router_state_tree__: JSON.stringify(flightRouterState),
}
if (prefetch) {
// Enable prefetch response
headers.__flight_prefetch__ = '1'
headers.__next_router_prefetch__ = '1'
}

const res = await fetch(url.toString(), {
Expand Down
14 changes: 7 additions & 7 deletions packages/next/server/app-render.tsx
Expand Up @@ -582,9 +582,9 @@ function getScriptNonceFromHeader(cspHeaderValue: string): string | undefined {
}

const FLIGHT_PARAMETERS = [
'__flight__',
'__flight_router_state_tree__',
'__flight_prefetch__',
'__rsc__',
'__next_router_state_tree__',
'__next_router_prefetch__',
] as const

function headersWithoutFlight(headers: IncomingHttpHeaders) {
Expand Down Expand Up @@ -653,8 +653,8 @@ export async function renderToHTMLOrFlight(
// don't modify original query object
query = Object.assign({}, query)

const isFlight = req.headers.__flight__ !== undefined
const isPrefetch = req.headers.__flight_prefetch__ !== undefined
const isFlight = req.headers.__rsc__ !== undefined
const isPrefetch = req.headers.__next_router_prefetch__ !== undefined

// Handle client-side navigation to pages directory
if (isFlight && isPagesDir) {
Expand Down Expand Up @@ -688,8 +688,8 @@ export async function renderToHTMLOrFlight(
* Router state provided from the client-side router. Used to handle rendering from the common layout down.
*/
const providedFlightRouterState: FlightRouterState = isFlight
? req.headers.__flight_router_state_tree__
? JSON.parse(req.headers.__flight_router_state_tree__ as string)
? req.headers.__next_router_state_tree__
? JSON.parse(req.headers.__next_router_state_tree__ as string)
: {}
: undefined

Expand Down
4 changes: 2 additions & 2 deletions packages/next/server/base-server.ts
Expand Up @@ -1028,9 +1028,9 @@ export default abstract class Server<ServerOptions extends Options = Options> {
)
}

// Don't delete query.__flight__ yet, it still needs to be used in renderToHTML later
// Don't delete query.__rsc__ yet, it still needs to be used in renderToHTML later
const isFlightRequest = Boolean(
this.serverComponentManifest && req.headers.__flight__
this.serverComponentManifest && req.headers.__rsc__
)

// we need to ensure the status code if /404 is visited directly
Expand Down
6 changes: 3 additions & 3 deletions packages/next/server/internal-utils.ts
Expand Up @@ -6,10 +6,10 @@ const INTERNAL_QUERY_NAMES = [
'__nextDefaultLocale',
'__nextIsNotFound',
// RSC
'__flight__',
'__rsc__',
// Routing
'__flight_router_state_tree__',
'__flight_prefetch__',
'__next_router_state_tree__',
'__next_router_prefetch__',
] as const

const EXTENDED_INTERNAL_QUERY_NAMES = ['__nextDataReq'] as const
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/next-server.ts
Expand Up @@ -828,7 +828,7 @@ export default class NextNodeServer extends BaseServer {

if (
this.nextConfig.experimental.appDir &&
(renderOpts.isAppPath || req.headers.__flight__)
(renderOpts.isAppPath || req.headers.__rsc__)
) {
const isPagesDir = !renderOpts.isAppPath
return appRenderToHTMLOrFlight(
Expand Down
6 changes: 3 additions & 3 deletions packages/next/server/web/adapter.ts
Expand Up @@ -36,9 +36,9 @@ class NextRequestHint extends NextRequest {
}

const FLIGHT_PARAMETERS = [
'__flight__',
'__flight_router_state_tree__',
'__flight_prefetch__',
'__rsc__',
'__next_router_state_tree__',
'__next_router_prefetch__',
] as const

export async function adapter(params: {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/middleware.js
Expand Up @@ -19,7 +19,7 @@ export function middleware(request) {
? 'rewrite'
: 'redirect'

const internal = ['__flight__', '__flight_router_state_tree__']
const internal = ['__rsc__', '__next_router_state_tree__']
if (internal.some((name) => request.headers.has(name))) {
return NextResponse[method](new URL('/internal/failure', request.url))
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -42,7 +42,7 @@ describe('app dir', () => {
{},
{
headers: {
__flight__: '1',
__rsc__: '1',
},
}
)
Expand All @@ -56,7 +56,7 @@ describe('app dir', () => {
{},
{
headers: {
__flight__: '1',
__rsc__: '1',
},
}
)
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/app-dir/rsc-basic.test.ts
Expand Up @@ -91,9 +91,9 @@ describe('app dir - react server components', () => {
'__nextLocale',
'__nextDefaultLocale',
'__nextIsNotFound',
'__flight__',
'__flight_router_state_tree__',
'__flight_prefetch__',
'__rsc__',
'__next_router_state_tree__',
'__next_router_prefetch__',
]

const hasNextInternalQuery = inlineFlightContents.some((content) =>
Expand All @@ -111,9 +111,9 @@ describe('app dir - react server components', () => {
requestsCount++
return request.allHeaders().then((headers) => {
if (
headers.__flight__ === '1' &&
// Prefetches also include `__flight__`
headers.__flight_prefetch__ !== '1'
headers.__rsc__ === '1' &&
// Prefetches also include `__rsc__`
headers.__next_router_prefetch__ !== '1'
) {
hasFlightRequest = true
}
Expand Down Expand Up @@ -197,8 +197,8 @@ describe('app dir - react server components', () => {
page.on('request', (request) => {
return request.allHeaders().then((headers) => {
if (
headers.__flight__ === '1' &&
headers.__flight_prefetch__ !== '1'
headers.__rsc__ === '1' &&
headers.__next_router_prefetch__ !== '1'
) {
hasFlightRequest = true
}
Expand Down Expand Up @@ -337,7 +337,7 @@ describe('app dir - react server components', () => {
{},
{
headers: {
__flight__: '1',
__rsc__: '1',
},
}
).then(async (response) => {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/switchable-runtime/index.test.ts
Expand Up @@ -120,7 +120,7 @@ describe('Switchable runtime', () => {
beforePageLoad(page) {
page.on('request', (request) => {
return request.allHeaders().then((headers) => {
if (headers.__flight__ === '1') {
if (headers.__rsc__ === '1') {
flightRequest = request.url()
}
})
Expand Down Expand Up @@ -680,7 +680,7 @@ describe('Switchable runtime', () => {
beforePageLoad(page) {
page.on('request', (request) => {
request.allHeaders().then((headers) => {
if (headers.__flight__ === '1') {
if (headers.__rsc__ === '1') {
flightRequest = request.url()
}
})
Expand Down

0 comments on commit 3a4db8a

Please sign in to comment.