Skip to content

Commit

Permalink
Fix edge rewrite handling (#40115)
Browse files Browse the repository at this point in the history
Follow-up to #40076 this ensures we handle rendering correctly when the URL doesn't match the edge function exactly e.g. when rewriting since it looks like we don't currently have access to the `x-matched-path` header like we do for serverless functions. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/runs/8102187444?check_suite_focus=true

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
  • Loading branch information
ijjk and huozhi committed Aug 30, 2022
1 parent 68fb39a commit 29582c8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/next/server/base-server.ts
Expand Up @@ -1578,6 +1578,18 @@ export default abstract class Server<ServerOptions extends Options = Options> {
if (result !== false) return result
}
}

// currently edge functions aren't receiving the x-matched-path
// header so we need to fallback to matching the current page
// when we weren't able to match via dynamic route to handle
// the rewrite case
// @ts-expect-error extended in child class web-server
if (this.serverOptions.webServerConfig) {
// @ts-expect-error extended in child class web-server
ctx.pathname = this.serverOptions.webServerConfig.page
const result = await this.renderPageComponent(ctx, bubbleNoFallback)
if (result !== false) return result
}
} catch (error) {
const err = getProperError(error)

Expand Down

0 comments on commit 29582c8

Please sign in to comment.