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( ...@@ -421,8 +421,9 @@ export async function renderToHTML(
} }
const key = segmentParam.param const key = segmentParam.param
const value = pathParams[key]
if (!pathParams[key] && !query[key]) { if (!value) {
if (segmentParam.type === 'optional-catchall') { if (segmentParam.type === 'optional-catchall') {
return { return {
param: key, param: key,
...@@ -433,9 +434,6 @@ export async function renderToHTML( ...@@ -433,9 +434,6 @@ export async function renderToHTML(
return null 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 { return {
param: key, param: key,
value: value, value: value,
......
...@@ -221,7 +221,8 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -221,7 +221,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
protected abstract findPageComponents( protected abstract findPageComponents(
pathname: string, pathname: string,
query?: NextParsedUrlQuery, query?: NextParsedUrlQuery,
params?: Params params?: Params,
isAppDir?: boolean
): Promise<FindComponentsResult | null> ): Promise<FindComponentsResult | null>
protected abstract getPagePath(pathname: string, locales?: string[]): string protected abstract getPagePath(pathname: string, locales?: string[]): string
protected abstract getFontManifest(): FontManifest | undefined protected abstract getFontManifest(): FontManifest | undefined
...@@ -1795,10 +1796,12 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1795,10 +1796,12 @@ export default abstract class Server<ServerOptions extends Options = Options> {
if (typeof appPath === 'string') { if (typeof appPath === 'string') {
page = appPath page = appPath
} }
const result = await this.findPageComponents( const result = await this.findPageComponents(
page, page,
query, query,
ctx.renderOpts.params ctx.renderOpts.params,
typeof appPath === 'string'
) )
if (result) { if (result) {
try { try {
......
...@@ -1105,7 +1105,8 @@ export default class DevServer extends Server { ...@@ -1105,7 +1105,8 @@ export default class DevServer extends Server {
protected async findPageComponents( protected async findPageComponents(
pathname: string, pathname: string,
query: ParsedUrlQuery = {}, query: ParsedUrlQuery = {},
params: Params | null = null params: Params | null = null,
isAppDir: boolean = false
): Promise<FindComponentsResult | null> { ): Promise<FindComponentsResult | null> {
await this.devReady await this.devReady
const compilationErr = await this.getCompilationError(pathname) const compilationErr = await this.getCompilationError(pathname)
...@@ -1124,7 +1125,7 @@ export default class DevServer extends Server { ...@@ -1124,7 +1125,7 @@ export default class DevServer extends Server {
this.serverComponentManifest = super.getServerComponentManifest() this.serverComponentManifest = super.getServerComponentManifest()
} }
return super.findPageComponents(pathname, query, params) return super.findPageComponents(pathname, query, params, isAppDir)
} catch (err) { } catch (err) {
if ((err as any).code !== 'ENOENT') { if ((err as any).code !== 'ENOENT') {
throw err throw err
......
...@@ -683,7 +683,8 @@ export default class NextNodeServer extends BaseServer { ...@@ -683,7 +683,8 @@ export default class NextNodeServer extends BaseServer {
protected async findPageComponents( protected async findPageComponents(
pathname: string, pathname: string,
query: NextParsedUrlQuery = {}, query: NextParsedUrlQuery = {},
params: Params | null = null params: Params | null = null,
isAppDir: boolean = false
): Promise<FindComponentsResult | null> { ): Promise<FindComponentsResult | null> {
let paths = [ let paths = [
// try serving a static AMP version first // try serving a static AMP version first
...@@ -732,7 +733,8 @@ export default class NextNodeServer extends BaseServer { ...@@ -732,7 +733,8 @@ export default class NextNodeServer extends BaseServer {
__flight__: query.__flight__, __flight__: query.__flight__,
} as NextParsedUrlQuery) } as NextParsedUrlQuery)
: query), : query),
...(params || {}), // For appDir params is excluded.
...((isAppDir ? {} : params) || {}),
}, },
} }
} catch (err) { } 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