Skip to content

Commit

Permalink
Move normalizing of query for edge (#48373)
Browse files Browse the repository at this point in the history
Follow-up to #48370 this just
moves the normalizing to the adapter instead of the web-server so it's
in a more specific place.
  • Loading branch information
ijjk committed Apr 14, 2023
1 parent 26a35a4 commit 43519cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
13 changes: 0 additions & 13 deletions packages/next/src/server/web-server.ts
Expand Up @@ -23,7 +23,6 @@ import { isDynamicRoute } from '../shared/lib/router/utils'
import { interpolateDynamicPath, normalizeVercelUrl } from './server-utils'
import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex'
import { IncrementalCache } from './lib/incremental-cache'
import { NEXT_QUERY_PARAM_PREFIX } from '../lib/constants'
interface WebServerOptions extends Options {
webServerConfig: {
page: string
Expand Down Expand Up @@ -105,18 +104,6 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
res: BaseNextResponse,
parsedUrl: UrlWithParsedQuery
): 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)
}
protected async hasPage(page: string) {
Expand Down
18 changes: 18 additions & 0 deletions packages/next/src/server/web/adapter.ts
Expand Up @@ -16,6 +16,7 @@ import {
NEXT_ROUTER_STATE_TREE,
RSC,
} from '../../client/components/app-router-headers'
import { NEXT_QUERY_PARAM_PREFIX } from '../../lib/constants'

declare const _ENTRIES: any

Expand Down Expand Up @@ -70,6 +71,23 @@ export async function adapter(
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.
const buildId = requestUrl.buildId
requestUrl.buildId = ''
Expand Down

0 comments on commit 43519cf

Please sign in to comment.