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

Rename query to searchParams for getServerSideProps in new Router #38654

Merged
merged 5 commits into from Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 3 deletions packages/next/server/app-render.tsx
Expand Up @@ -651,7 +651,7 @@ export async function renderToHTML(
}

type getServerSidePropsContextPage = GetServerSidePropsContext & {
query: URLSearchParams
searchParams: URLSearchParams
pathname: string
}

Expand All @@ -668,7 +668,7 @@ export async function renderToHTML(
cookies,
layoutSegments: segmentPath,
// TODO-APP: change pathname to actual pathname, it holds the dynamic parameter currently
...(isPage ? { query, pathname } : {}),
...(isPage ? { searchParams: query, pathname } : {}),
...(pageIsDynamic ? { params: currentParams } : undefined),
...(isPreview
? { preview: true, previewData: previewData }
Expand Down Expand Up @@ -729,7 +729,7 @@ export async function renderToHTML(
// If you have a `/dashboard/[team]/layout.js` it will provide `team` as a param but not anything further down.
params={currentParams}
// Query is only provided to page
{...(isPage ? { query } : {})}
{...(isPage ? { searchParams: query } : {})}
/>
)
},
Expand Down
10 changes: 7 additions & 3 deletions test/e2e/app-dir/app/app/param-and-query/[slug]/page.client.js
@@ -1,7 +1,11 @@
export default function Page({ params, query }) {
export default function Page({ params, searchParams }) {
return (
<h1 id="params-and-query" data-params={params.slug} data-query={query.slug}>
hello from /param-and-query/{params.slug}?slug={query.slug}
<h1
id="params-and-query"
data-params={params.slug}
data-query={searchParams.slug}
>
hello from /param-and-query/{params.slug}?slug={searchParams.slug}
</h1>
)
}
4 changes: 2 additions & 2 deletions test/e2e/app-dir/rsc-basic/app/next-api/link/page.server.js
Expand Up @@ -18,10 +18,10 @@ export default function LinkPage({ queryId }) {

export function getServerSideProps(ctx) {
// FIXME: query is missing
const { query } = ctx
const { searchParams } = ctx
return {
props: {
queryId: query.id || '0',
queryId: searchParams.id || '0',
},
}
}