Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
f05cee2d
Unverified
Commit
f05cee2d
authored
Jul 15, 2022
by
Tim Neutkens
Committed by
GitHub
Jul 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename query to searchParams for getServerSideProps in new Router (#38654)
parent
3430ac15
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
33 deletions
+66
-33
app-render.tsx
packages/next/server/app-render.tsx
+17
-4
page.client.js
...e2e/app-dir/app/app/param-and-query/[slug]/page.client.js
+7
-3
index.test.ts
test/e2e/app-dir/index.test.ts
+39
-23
rendering.test.ts
test/e2e/app-dir/rendering.test.ts
+1
-1
page.server.js
test/e2e/app-dir/rsc-basic/app/next-api/link/page.server.js
+2
-2
No files found.
packages/next/server/app-render.tsx
View file @
f05cee2d
...
@@ -651,7 +651,18 @@ export async function renderToHTML(
...
@@ -651,7 +651,18 @@ export async function renderToHTML(
}
}
type
getServerSidePropsContextPage
=
GetServerSidePropsContext
&
{
type
getServerSidePropsContextPage
=
GetServerSidePropsContext
&
{
query
:
URLSearchParams
searchParams
:
URLSearchParams
pathname
:
string
}
type
GetStaticPropsContext
=
{
layoutSegments
:
FlightSegmentPath
params
?:
{
[
key
:
string
]:
string
|
string
[]
}
preview
?:
boolean
previewData
?:
string
|
object
|
undefined
}
type
GetStaticPropContextPage
=
GetStaticPropsContext
&
{
pathname
:
string
pathname
:
string
}
}
...
@@ -668,7 +679,7 @@ export async function renderToHTML(
...
@@ -668,7 +679,7 @@ export async function renderToHTML(
cookies
,
cookies
,
layoutSegments
:
segmentPath
,
layoutSegments
:
segmentPath
,
// TODO-APP: change pathname to actual pathname, it holds the dynamic parameter currently
// TODO-APP: change pathname to actual pathname, it holds the dynamic parameter currently
...(
isPage
?
{
query
,
pathname
}
:
{}),
...(
isPage
?
{
searchParams
:
query
,
pathname
}
:
{}),
...(
pageIsDynamic
?
{
params
:
currentParams
}
:
undefined
),
...(
pageIsDynamic
?
{
params
:
currentParams
}
:
undefined
),
...(
isPreview
...(
isPreview
?
{
preview
:
true
,
previewData
:
previewData
}
?
{
preview
:
true
,
previewData
:
previewData
}
...
@@ -681,7 +692,9 @@ export async function renderToHTML(
...
@@ -681,7 +692,9 @@ export async function renderToHTML(
}
}
// TODO-APP: implement layout specific caching for getStaticProps
// TODO-APP: implement layout specific caching for getStaticProps
if
(
layoutOrPageMod
.
getStaticProps
)
{
if
(
layoutOrPageMod
.
getStaticProps
)
{
const
getStaticPropsContext
=
{
const
getStaticPropsContext
:
|
GetStaticPropsContext
|
GetStaticPropContextPage
=
{
layoutSegments
:
segmentPath
,
layoutSegments
:
segmentPath
,
...(
isPage
?
{
pathname
}
:
{}),
...(
isPage
?
{
pathname
}
:
{}),
...(
pageIsDynamic
?
{
params
:
currentParams
}
:
undefined
),
...(
pageIsDynamic
?
{
params
:
currentParams
}
:
undefined
),
...
@@ -729,7 +742,7 @@ export async function renderToHTML(
...
@@ -729,7 +742,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.
// If you have a `/dashboard/[team]/layout.js` it will provide `team` as a param but not anything further down.
params=
{
currentParams
}
params=
{
currentParams
}
// Query is only provided to page
// Query is only provided to page
{
...
(
isPage
?
{
query
}
:
{})}
{
...
(
isPage
?
{
searchParams
:
query
}
:
{})}
/>
/>
)
)
},
},
...
...
test/e2e/app-dir/app/app/param-and-query/[slug]/page.client.js
View file @
f05cee2d
export
default
function
Page
({
params
,
query
})
{
export
default
function
Page
({
params
,
searchParams
})
{
return
(
return
(
<
h1
id
=
"params-and-query"
data
-
params
=
{
params
.
slug
}
data
-
query
=
{
query
.
slug
}
>
<
h1
hello
from
/param-and-query/
{
params
.
slug
}?
slug
=
{
query
.
slug
}
id
=
"params-and-query"
data
-
params
=
{
params
.
slug
}
data
-
query
=
{
searchParams
.
slug
}
>
hello
from
/param-and-query/
{
params
.
slug
}?
slug
=
{
searchParams
.
slug
}
<
/h1
>
<
/h1
>
)
)
}
}
test/e2e/app-dir/index.test.ts
View file @
f05cee2d
...
@@ -6,6 +6,8 @@ import cheerio from 'cheerio'
...
@@ -6,6 +6,8 @@ import cheerio from 'cheerio'
import
webdriver
from
'next-webdriver'
import
webdriver
from
'next-webdriver'
describe
(
'app dir'
,
()
=>
{
describe
(
'app dir'
,
()
=>
{
const
isDev
=
(
global
as
any
).
isNextDev
if
((
global
as
any
).
isNextDeploy
)
{
if
((
global
as
any
).
isNextDeploy
)
{
it
(
'should skip next deploy for now'
,
()
=>
{})
it
(
'should skip next deploy for now'
,
()
=>
{})
return
return
...
@@ -211,7 +213,10 @@ describe('app dir', () => {
...
@@ -211,7 +213,10 @@ describe('app dir', () => {
expect
(
html
).
toContain
(
'hello from app/dashboard'
)
expect
(
html
).
toContain
(
'hello from app/dashboard'
)
})
})
it
(
'should not rerender layout when navigating between routes in the same layout'
,
async
()
=>
{
// TODO-APP: Enable in development
;(
isDev
?
it
.
skip
:
it
)(
'should not rerender layout when navigating between routes in the same layout'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/same-layout/first'
)
const
browser
=
await
webdriver
(
next
.
url
,
'/same-layout/first'
)
try
{
try
{
...
@@ -234,10 +239,12 @@ describe('app dir', () => {
...
@@ -234,10 +239,12 @@ describe('app dir', () => {
}
finally
{
}
finally
{
await
browser
.
close
()
await
browser
.
close
()
}
}
})
}
)
describe
(
'<Link />'
,
()
=>
{
describe
(
'<Link />'
,
()
=>
{
it
(
'should hard push'
,
async
()
=>
{
// TODO-APP: fix development test
it
.
skip
(
'should hard push'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/link-hard-push'
)
const
browser
=
await
webdriver
(
next
.
url
,
'/link-hard-push'
)
try
{
try
{
...
@@ -264,7 +271,8 @@ describe('app dir', () => {
...
@@ -264,7 +271,8 @@ describe('app dir', () => {
}
}
})
})
it
(
'should hard replace'
,
async
()
=>
{
// TODO-APP: fix development test
it
.
skip
(
'should hard replace'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/link-hard-replace'
)
const
browser
=
await
webdriver
(
next
.
url
,
'/link-hard-replace'
)
try
{
try
{
...
@@ -954,7 +962,11 @@ describe('app dir', () => {
...
@@ -954,7 +962,11 @@ describe('app dir', () => {
'/client-with-errors/get-static-props'
'/client-with-errors/get-static-props'
)
)
expect
(
res
.
status
).
toBe
(
500
)
expect
(
res
.
status
).
toBe
(
500
)
expect
(
await
res
.
text
()).
toContain
(
'Internal Server Error'
)
expect
(
await
res
.
text
()).
toContain
(
isDev
?
'getStaticProps is not supported on Client Components'
:
'Internal Server Error'
)
})
})
it
(
'should throw an error when getServerSideProps is used'
,
async
()
=>
{
it
(
'should throw an error when getServerSideProps is used'
,
async
()
=>
{
...
@@ -963,7 +975,11 @@ describe('app dir', () => {
...
@@ -963,7 +975,11 @@ describe('app dir', () => {
'/client-with-errors/get-server-side-props'
'/client-with-errors/get-server-side-props'
)
)
expect
(
res
.
status
).
toBe
(
500
)
expect
(
res
.
status
).
toBe
(
500
)
expect
(
await
res
.
text
()).
toContain
(
'Internal Server Error'
)
expect
(
await
res
.
text
()).
toContain
(
isDev
?
'getServerSideProps is not supported on Client Components'
:
'Internal Server Error'
)
})
})
})
})
...
...
test/e2e/app-dir/rendering.test.ts
View file @
f05cee2d
...
@@ -15,7 +15,7 @@ describe('app dir rendering', () => {
...
@@ -15,7 +15,7 @@ describe('app dir rendering', () => {
return
return
}
}
const
isDev
=
(
global
as
any
).
isDev
const
isDev
=
(
global
as
any
).
is
Next
Dev
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
test/e2e/app-dir/rsc-basic/app/next-api/link/page.server.js
View file @
f05cee2d
...
@@ -18,10 +18,10 @@ export default function LinkPage({ queryId }) {
...
@@ -18,10 +18,10 @@ export default function LinkPage({ queryId }) {
export
function
getServerSideProps
(
ctx
)
{
export
function
getServerSideProps
(
ctx
)
{
// FIXME: query is missing
// FIXME: query is missing
const
{
query
}
=
ctx
const
{
searchParams
}
=
ctx
return
{
return
{
props
:
{
props
:
{
queryId
:
query
.
id
||
'0'
,
queryId
:
searchParams
.
id
||
'0'
,
},
},
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment