Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dynamic params from query in new router #38466

Merged
merged 6 commits into from Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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