Skip to content

Commit f23da82

Browse files
piehascorbicmrstork
authoredMay 1, 2024
fix: don't normalize url if x-nextjs-redirect header is present (#424)
* move next redirect up * refresh nextRedirect as it might have been changed since first read --------- Co-authored-by: Matt Kane <m@mk.gg> Co-authored-by: Mateusz Bocian <mrstork@users.noreply.github.com>
1 parent 16f808f commit f23da82

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎edge-runtime/lib/response.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ export const buildResponse = async ({
118118

119119
let rewrite = res.headers.get('x-middleware-rewrite')
120120
let redirect = res.headers.get('location')
121+
let nextRedirect = res.headers.get('x-nextjs-redirect')
121122

122123
// Data requests (i.e. requests for /_next/data ) need special handling
123124
const isDataReq = request.headers.has('x-nextjs-data')
124125
// Data requests need to be normalized to the route path
125-
if (isDataReq && !redirect && !rewrite) {
126+
if (isDataReq && !redirect && !rewrite && !nextRedirect) {
126127
const requestUrl = new URL(request.url)
127128
const normalizedDataUrl = normalizeDataUrl(requestUrl.pathname)
128129
// Don't rewrite unless the URL has changed
@@ -209,7 +210,7 @@ export const buildResponse = async ({
209210
res.headers.set('x-nextjs-redirect', relativizeURL(redirect, request.url))
210211
}
211212

212-
const nextRedirect = res.headers.get('x-nextjs-redirect')
213+
nextRedirect = res.headers.get('x-nextjs-redirect')
213214

214215
if (nextRedirect && isDataReq) {
215216
res.headers.set('x-nextjs-redirect', normalizeDataUrl(nextRedirect))

0 commit comments

Comments
 (0)
Please sign in to comment.