Skip to content

Commit 29582c8

Browse files
ijjkhuozhi
andauthored
Fix edge rewrite handling (#40115)
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>
1 parent 68fb39a commit 29582c8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/next/server/base-server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,18 @@ export default abstract class Server<ServerOptions extends Options = Options> {
15781578
if (result !== false) return result
15791579
}
15801580
}
1581+
1582+
// currently edge functions aren't receiving the x-matched-path
1583+
// header so we need to fallback to matching the current page
1584+
// when we weren't able to match via dynamic route to handle
1585+
// the rewrite case
1586+
// @ts-expect-error extended in child class web-server
1587+
if (this.serverOptions.webServerConfig) {
1588+
// @ts-expect-error extended in child class web-server
1589+
ctx.pathname = this.serverOptions.webServerConfig.page
1590+
const result = await this.renderPageComponent(ctx, bubbleNoFallback)
1591+
if (result !== false) return result
1592+
}
15811593
} catch (error) {
15821594
const err = getProperError(error)
15831595

0 commit comments

Comments
 (0)