Skip to content

Commit

Permalink
Fix page url for edge routes in app dir
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 8, 2022
1 parent ba4c575 commit 2a571e2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/next/server/next-server.ts
Expand Up @@ -763,7 +763,6 @@ export default class NextNodeServer extends BaseServer {
params,
page,
appPaths: null,
isAppPath: false,
})

if (handledAsEdgeFunction) {
Expand Down Expand Up @@ -913,7 +912,6 @@ export default class NextNodeServer extends BaseServer {
params: ctx.renderOpts.params,
page,
appPaths,
isAppPath,
})
return null
}
Expand Down Expand Up @@ -2031,7 +2029,6 @@ export default class NextNodeServer extends BaseServer {
params: Params | undefined
page: string
appPaths: string[] | null
isAppPath: boolean
onWarning?: (warning: Error) => void
}): Promise<FetchEventResult | null> {
let middlewareInfo: ReturnType<typeof this.getEdgeFunctionInfo> | undefined
Expand All @@ -2047,12 +2044,16 @@ export default class NextNodeServer extends BaseServer {
return null
}

// Erase extra queries
const locale = params.query.__nextLocale
delete params.query.__nextLocale
delete params.query.__nextDefaultLocale

// For middleware to "fetch" we must always provide an absolute URL
const isDataReq = !!params.query.__nextDataReq
const query = urlQueryToSearchParams(params.query).toString()
const locale = params.query.__nextLocale
// Use original pathname (without `/page`) instead of appPath for url
let normalizedPathname = params.page

let normalizedPathname = params.req.url

if (isDataReq) {
params.req.headers['x-nextjs-data'] = '1'
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/app-dir/rsc-basic.test.ts
Expand Up @@ -340,6 +340,20 @@ describe('app dir - react server components', () => {
expect(head).toMatch(/{color:(\s*)blue;?}/)
})

it('should stick to the url without trailing /page suffix', async () => {
const browser = await webdriver(next.url, '/edge/dynamic')
const indexUrl = await browser.url()

await browser.loadPage(`${next.url}/edge/dynamic/123`, {
disableCache: false,
beforePageLoad: null,
})

const dynamicRouteUrl = await browser.url()
expect(indexUrl).toBe(`${next.url}/edge/dynamic`)
expect(dynamicRouteUrl).toBe(`${next.url}/edge/dynamic/123`)
})

it('should support streaming for flight response', async () => {
await fetchViaHTTP(next.url, '/?__flight__=1').then(async (response) => {
const result = await resolveStreamResponse(response)
Expand Down
@@ -0,0 +1,7 @@
export default function page() {
return 'dynamic route [id] page'
}

export const runtime = {
runtime: 'experimental-edge',
}
7 changes: 7 additions & 0 deletions test/e2e/app-dir/rsc-basic/app/edge/dynamic/page.server.js
@@ -0,0 +1,7 @@
export default function page() {
return 'dynamic route index page'
}

export const runtime = {
runtime: 'experimental-edge',
}

0 comments on commit 2a571e2

Please sign in to comment.