Unverified Commit 1e451ab7 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix req.url of rsc dynamic routes pages gSSP in edge runtime (#36134)

We were feeding pathname like `/routes/[dynamic]` as `req.url` to RSC pages in edge runtime, which is not aligned with node runtime

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent d24eeb64
...@@ -125,7 +125,7 @@ export default class NextWebServer extends BaseServer { ...@@ -125,7 +125,7 @@ export default class NextWebServer extends BaseServer {
): Promise<RenderResult | null> { ): Promise<RenderResult | null> {
return renderToHTML( return renderToHTML(
{ {
url: pathname, url: req.url,
cookies: req.cookies, cookies: req.cookies,
headers: req.headers, headers: req.headers,
} as any, } as any,
......
export default function Pid({ text }) { import { parse } from 'url'
return <div>{`query: ${text}`}</div>
export default function Pid({ text, pathname }) {
return (
<>
<div>{`query: ${text}`}</div>
<div>{`pathname: ${pathname}`}</div>
</>
)
} }
export function getServerSideProps({ params }) { export function getServerSideProps({ params, req }) {
return { return {
props: { props: {
pathname: parse(req.url).pathname,
text: params.dynamic, text: params.dynamic,
}, },
} }
......
...@@ -10,20 +10,6 @@ export default async function basic(context, { env }) { ...@@ -10,20 +10,6 @@ export default async function basic(context, { env }) {
expect(pathNotFoundHTML).toContain('custom-404-page') expect(pathNotFoundHTML).toContain('custom-404-page')
}) })
it('should render dynamic routes correctly', async () => {
const dynamicRoute1HTML = await renderViaHTTP(
context.appPort,
'/routes/dynamic1'
)
const dynamicRoute2HTML = await renderViaHTTP(
context.appPort,
'/routes/dynamic2'
)
expect(dynamicRoute1HTML).toContain('query: dynamic1')
expect(dynamicRoute2HTML).toContain('query: dynamic2')
})
it('should support api routes', async () => { it('should support api routes', async () => {
const res = await renderViaHTTP(context.appPort, '/api/ping') const res = await renderViaHTTP(context.appPort, '/api/ping')
expect(res).toContain('pong') expect(res).toContain('pong')
......
...@@ -102,6 +102,22 @@ export default function (context, { runtime, env }) { ...@@ -102,6 +102,22 @@ export default function (context, { runtime, env }) {
expect(await browser.eval('window.beforeNav')).toBe(1) expect(await browser.eval('window.beforeNav')).toBe(1)
}) })
it('should render dynamic routes correctly', async () => {
const dynamicRoute1HTML = await renderViaHTTP(
context.appPort,
'/routes/dynamic1'
)
const dynamicRoute2HTML = await renderViaHTTP(
context.appPort,
'/routes/dynamic2'
)
expect(dynamicRoute1HTML).toContain('query: dynamic1')
expect(dynamicRoute1HTML).toContain('pathname: /routes/dynamic')
expect(dynamicRoute2HTML).toContain('query: dynamic2')
expect(dynamicRoute2HTML).toContain('pathname: /routes/dynamic')
})
it('should be able to navigate between rsc pages', async () => { it('should be able to navigate between rsc pages', async () => {
let content let content
const browser = await webdriver(context.appPort, '/') const browser = await webdriver(context.appPort, '/')
......
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