Unverified Commit 43519cf5 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Move normalizing of query for edge (#48373)

Follow-up to https://github.com/vercel/next.js/pull/48370 this just
moves the normalizing to the adapter instead of the web-server so it's
in a more specific place.
parent 26a35a47
...@@ -23,7 +23,6 @@ import { isDynamicRoute } from '../shared/lib/router/utils' ...@@ -23,7 +23,6 @@ import { isDynamicRoute } from '../shared/lib/router/utils'
import { interpolateDynamicPath, normalizeVercelUrl } from './server-utils' import { interpolateDynamicPath, normalizeVercelUrl } from './server-utils'
import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex' import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex'
import { IncrementalCache } from './lib/incremental-cache' import { IncrementalCache } from './lib/incremental-cache'
import { NEXT_QUERY_PARAM_PREFIX } from '../lib/constants'
interface WebServerOptions extends Options { interface WebServerOptions extends Options {
webServerConfig: { webServerConfig: {
page: string page: string
...@@ -105,18 +104,6 @@ export default class NextWebServer extends BaseServer<WebServerOptions> { ...@@ -105,18 +104,6 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
res: BaseNextResponse, res: BaseNextResponse,
parsedUrl: UrlWithParsedQuery parsedUrl: UrlWithParsedQuery
): Promise<void> { ): Promise<void> {
for (const key of Object.keys(parsedUrl.query)) {
const value = parsedUrl.query[key]
if (
key !== NEXT_QUERY_PARAM_PREFIX &&
key.startsWith(NEXT_QUERY_PARAM_PREFIX)
) {
const normalizedKey = key.substring(NEXT_QUERY_PARAM_PREFIX.length)
parsedUrl.query[normalizedKey] = value
delete parsedUrl.query[key]
}
}
super.run(req, res, parsedUrl) super.run(req, res, parsedUrl)
} }
protected async hasPage(page: string) { protected async hasPage(page: string) {
......
...@@ -16,6 +16,7 @@ import { ...@@ -16,6 +16,7 @@ import {
NEXT_ROUTER_STATE_TREE, NEXT_ROUTER_STATE_TREE,
RSC, RSC,
} from '../../client/components/app-router-headers' } from '../../client/components/app-router-headers'
import { NEXT_QUERY_PARAM_PREFIX } from '../../lib/constants'
declare const _ENTRIES: any declare const _ENTRIES: any
...@@ -70,6 +71,23 @@ export async function adapter( ...@@ -70,6 +71,23 @@ export async function adapter(
nextConfig: params.request.nextConfig, nextConfig: params.request.nextConfig,
}) })
for (const key of requestUrl.searchParams.keys()) {
const value = requestUrl.searchParams.getAll(key)
if (
key !== NEXT_QUERY_PARAM_PREFIX &&
key.startsWith(NEXT_QUERY_PARAM_PREFIX)
) {
const normalizedKey = key.substring(NEXT_QUERY_PARAM_PREFIX.length)
requestUrl.searchParams.delete(normalizedKey)
for (const val of value) {
requestUrl.searchParams.append(normalizedKey, val)
}
requestUrl.searchParams.delete(key)
}
}
// Ensure users only see page requests, never data requests. // Ensure users only see page requests, never data requests.
const buildId = requestUrl.buildId const buildId = requestUrl.buildId
requestUrl.buildId = '' requestUrl.buildId = ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment