Unverified Commit 20f31203 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

[next-server] preserve rsc query for rsc redirects (#78876)

Backport of #77963 to 15.3.x
Co-authored-by: 's avatarJiachi Liu <inbox@huozhi.im>
parent b464d185
...@@ -11,7 +11,6 @@ import { ...@@ -11,7 +11,6 @@ import {
INTERCEPTION_ROUTE_MARKERS, INTERCEPTION_ROUTE_MARKERS,
isInterceptionRouteAppPath, isInterceptionRouteAppPath,
} from './interception-routes' } from './interception-routes'
import { NEXT_RSC_UNION_QUERY } from '../../../../client/components/app-router-headers'
import { getCookieParser } from '../../../../server/api-utils/get-cookie-parser' import { getCookieParser } from '../../../../server/api-utils/get-cookie-parser'
import type { Params } from '../../../../server/request/params' import type { Params } from '../../../../server/request/params'
...@@ -210,8 +209,6 @@ export function prepareDestination(args: { ...@@ -210,8 +209,6 @@ export function prepareDestination(args: {
query: NextParsedUrlQuery query: NextParsedUrlQuery
}) { }) {
const query = Object.assign({}, args.query) const query = Object.assign({}, args.query)
delete query[NEXT_RSC_UNION_QUERY]
const parsedDestination = parseDestination(args) const parsedDestination = parseDestination(args)
const { hostname: destHostname, query: destQuery } = parsedDestination const { hostname: destHostname, query: destQuery } = parsedDestination
......
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return (
<div>
<h1>Redirect Dest</h1>
</div>
)
}
import Link from 'next/link'
export default function Home() {
return (
<div>
{/* disable prefetch to align the dev/prod fetching behavior,
it's easier for writing tests */}
Go to{' '}
<Link prefetch={false} href="/redirect/source">
Redirect Link
</Link>
</div>
)
}
export default function Page() {
return (
<div>
<h1>Rewrite Dest</h1>
</div>
)
}
import Link from 'next/link'
export default function Home() {
return (
<div>
{/* disable prefetch to align the dev/prod fetching behavior,
it's easier for writing tests */}
Go to{' '}
<Link prefetch={false} href="/rewrite/source">
Rewrite Link
</Link>
</div>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
reactStrictMode: true,
async redirects() {
return [
{
source: '/redirect/source',
destination: '/redirect/dest',
permanent: true,
},
]
},
async rewrites() {
return [
{
source: '/rewrite/source',
destination: '/rewrite/dest',
},
]
},
}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
import { Request } from 'playwright'
describe('rsc-query-routing', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should contain rsc query in rsc request when redirect the page', async () => {
const browser = await next.browser('/redirect')
const rscRequestUrls: string[] = []
browser.on('request', (req: Request) => {
if (req.url().includes('?_rsc=')) {
rscRequestUrls.push(req.url())
}
})
// Click redirect link
const link = await browser.elementByCss('a')
await link.click()
// Wait for the page load to be completed
await retry(async () => {
expect(await browser.elementByCss('h1').text()).toBe('Redirect Dest')
})
// The redirect source and dest urls should both contain the rsc query
expect(rscRequestUrls[0]).toContain('/redirect/source')
expect(rscRequestUrls[1]).toContain('/redirect/dest')
})
it('should contain rsc query in rsc request when rewrite the page', async () => {
const browser = await next.browser('/rewrite')
const rscRequestUrls: string[] = []
browser.on('request', (req: Request) => {
if (req.url().includes('?_rsc=')) {
rscRequestUrls.push(req.url())
}
})
// Click redirect link
const link = await browser.elementByCss('a')
await link.click()
// Wait for the page load to be completed
await retry(async () => {
expect(await browser.elementByCss('h1').text()).toBe('Rewrite Dest')
})
// The rewrite source url should contain the rsc query
expect(rscRequestUrls[0]).toContain('/rewrite/source')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment