Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 87cedbb

Browse filesBrowse files
committed
fix: don't attempt to keep old query param working
1 parent f5bb340 commit 87cedbb
Copy full SHA for 87cedbb

File tree

Expand file treeCollapse file tree

2 files changed

+19
-14
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-14
lines changed

‎edge-runtime/lib/response.ts

Copy file name to clipboardExpand all lines: edge-runtime/lib/response.ts
+19-5Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
normalizeDataUrl,
1414
normalizeLocalePath,
1515
normalizeTrailingSlash,
16+
parseDataUrl,
1617
relativizeURL,
18+
removeBasePath,
19+
stripTrailingSlash,
1720
} from './util.ts'
1821

1922
export interface FetchEventResult {
@@ -181,12 +184,23 @@ export const buildResponse = async ({
181184

182185
if (isDataReq) {
183186
// The rewrite target is a data request, but a middleware rewrite target is always for the page route,
184-
// so we need to tell the server this is a data request. Setting the `x-nextjs-data` header is not enough. 🤷
185-
rewriteUrl.searchParams.set('__nextDataReq', '1')
186-
}
187+
// so we need to transform url back to data url
188+
189+
const { buildId } = parseDataUrl(
190+
removeBasePath(new URL(request.url).pathname, nextConfig?.basePath),
191+
)
192+
const rewriteRoute = removeBasePath(rewriteUrl.pathname, nextConfig?.basePath)
187193

188-
// respect trailing slash rules to prevent 308s
189-
rewriteUrl.pathname = normalizeTrailingSlash(rewriteUrl.pathname, nextConfig?.trailingSlash)
194+
const newPath = addBasePath(
195+
`/_next/data/${buildId}${rewriteRoute === '/' ? '/index' : stripTrailingSlash(rewriteRoute)}.json`,
196+
nextConfig?.basePath,
197+
)
198+
199+
rewriteUrl.pathname = newPath
200+
} else {
201+
// respect trailing slash rules to prevent 308s
202+
rewriteUrl.pathname = normalizeTrailingSlash(rewriteUrl.pathname, nextConfig?.trailingSlash)
203+
}
190204

191205
const target = normalizeLocalizedTarget({ target: rewriteUrl.toString(), request, nextConfig })
192206
if (target === request.url) {

‎src/run/handlers/server.ts

Copy file name to clipboardExpand all lines: src/run/handlers/server.ts
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,6 @@ export default async (request: Request) => {
8383
},
8484
})
8585

86-
if (new URL(request.url).searchParams.get('__nextDataReq')) {
87-
const NEXT_REQUEST_META = Symbol.for('NextInternalRequestMeta')
88-
// @ts-expect-error NEXT_REQUEST_META doesn't exist in IncomingMessage type
89-
const meta = req[NEXT_REQUEST_META] ?? {}
90-
meta.isNextDataReq = true
91-
// @ts-expect-error NEXT_REQUEST_META doesn't exist in IncomingMessage type
92-
req[NEXT_REQUEST_META] = meta
93-
}
94-
9586
disableFaultyTransferEncodingHandling(res as unknown as ComputeJsOutgoingMessage)
9687

9788
const requestContext = getRequestContext() ?? createRequestContext()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.