Unverified Commit 8282c819 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Remove dynamic params from `query` in new router (#38466)

Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent f7de771b
......@@ -421,8 +421,9 @@ export async function renderToHTML(
}
const key = segmentParam.param
const value = pathParams[key]
if (!pathParams[key] && !query[key]) {
if (!value) {
if (segmentParam.type === 'optional-catchall') {
return {
param: key,
......@@ -433,9 +434,6 @@ export async function renderToHTML(
return null
}
// TODO: this should only read from `pathParams`. There's an inconsistency where `query` holds params currently which has to be fixed.
const value = pathParams[key] ?? query[key]
return {
param: key,
value: value,
......
......@@ -221,7 +221,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
protected abstract findPageComponents(
pathname: string,
query?: NextParsedUrlQuery,
params?: Params
params?: Params,
isAppDir?: boolean
): Promise<FindComponentsResult | null>
protected abstract getPagePath(pathname: string, locales?: string[]): string
protected abstract getFontManifest(): FontManifest | undefined
......@@ -1795,10 +1796,12 @@ export default abstract class Server<ServerOptions extends Options = Options> {
if (typeof appPath === 'string') {
page = appPath
}
const result = await this.findPageComponents(
page,
query,
ctx.renderOpts.params
ctx.renderOpts.params,
typeof appPath === 'string'
)
if (result) {
try {
......
......@@ -1105,7 +1105,8 @@ export default class DevServer extends Server {
protected async findPageComponents(
pathname: string,
query: ParsedUrlQuery = {},
params: Params | null = null
params: Params | null = null,
isAppDir: boolean = false
): Promise<FindComponentsResult | null> {
await this.devReady
const compilationErr = await this.getCompilationError(pathname)
......@@ -1124,7 +1125,7 @@ export default class DevServer extends Server {
this.serverComponentManifest = super.getServerComponentManifest()
}
return super.findPageComponents(pathname, query, params)
return super.findPageComponents(pathname, query, params, isAppDir)
} catch (err) {
if ((err as any).code !== 'ENOENT') {
throw err
......
......@@ -683,7 +683,8 @@ export default class NextNodeServer extends BaseServer {
protected async findPageComponents(
pathname: string,
query: NextParsedUrlQuery = {},
params: Params | null = null
params: Params | null = null,
isAppDir: boolean = false
): Promise<FindComponentsResult | null> {
let paths = [
// try serving a static AMP version first
......@@ -732,7 +733,8 @@ export default class NextNodeServer extends BaseServer {
__flight__: query.__flight__,
} as NextParsedUrlQuery)
: query),
...(params || {}),
// For appDir params is excluded.
...((isAppDir ? {} : params) || {}),
},
}
} catch (err) {
......
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