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 4289aa2

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

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+14
-22
lines changed

‎edge-runtime/lib/response.ts

Copy file name to clipboardExpand all lines: edge-runtime/lib/response.ts
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
normalizeLocalePath,
1515
normalizeTrailingSlash,
1616
relativizeURL,
17+
removeBasePath,
18+
rewriteDataPath,
1719
} from './util.ts'
1820

1921
export interface FetchEventResult {
@@ -180,14 +182,16 @@ export const buildResponse = async ({
180182
}
181183

182184
if (isDataReq) {
183-
// 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')
185+
rewriteUrl.pathname = rewriteDataPath({
186+
dataUrl: new URL(request.url).pathname,
187+
newRoute: removeBasePath(rewriteUrl.pathname, nextConfig?.basePath),
188+
basePath: nextConfig?.basePath,
189+
})
190+
} else {
191+
// respect trailing slash rules to prevent 308s
192+
rewriteUrl.pathname = normalizeTrailingSlash(rewriteUrl.pathname, nextConfig?.trailingSlash)
186193
}
187194

188-
// respect trailing slash rules to prevent 308s
189-
rewriteUrl.pathname = normalizeTrailingSlash(rewriteUrl.pathname, nextConfig?.trailingSlash)
190-
191195
const target = normalizeLocalizedTarget({ target: rewriteUrl.toString(), request, nextConfig })
192196
if (target === request.url) {
193197
logger.withFields({ rewrite_url: rewrite }).debug('Rewrite url is same as original 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()

‎tests/e2e/edge-middleware.test.ts

Copy file name to clipboardExpand all lines: tests/e2e/edge-middleware.test.ts
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,11 @@ test('it should render OpenGraph image meta tag correctly', async ({ page, middl
5454
})
5555

5656
test('json data rewrite works', async ({ middlewarePages }) => {
57-
const response = await fetch(
58-
`${middlewarePages.url}/_next/data/build-id/sha.json?__nextDataReq=1`,
59-
{
60-
headers: {
61-
'x-nextjs-data': '1',
62-
},
57+
const response = await fetch(`${middlewarePages.url}/_next/data/build-id/sha.json`, {
58+
headers: {
59+
'x-nextjs-data': '1',
6360
},
64-
)
61+
})
6562

6663
expect(response.ok).toBe(true)
6764
const body = await response.text()

0 commit comments

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