Skip to content

Commit

Permalink
Remove dynamic params from query in new router (#38466)
Browse files Browse the repository at this point in the history
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 9, 2022
1 parent f7de771 commit 8282c81
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 2 additions & 4 deletions packages/next/server/app-render.tsx
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions packages/next/server/base-server.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions packages/next/server/dev/next-dev-server.ts
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions packages/next/server/next-server.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8282c81

Please sign in to comment.