Skip to content

Commit

Permalink
Rename query to searchParams for getServerSideProps in new Router
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Jul 14, 2022
1 parent 3430ac1 commit bba7395
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/next/server/app-render.tsx
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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',
},
}
}

0 comments on commit bba7395

Please sign in to comment.