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
0e48ea39
Unverified
Commit
0e48ea39
authored
Aug 13, 2020
by
Joe Haddad
Committed by
GitHub
Aug 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert next/client to TypeScript (#16167)
Fixes #16166
parent
09afc376
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
63 deletions
+124
-63
index.tsx
packages/next/client/index.tsx
+102
-46
router.ts
packages/next/next-server/lib/router/router.ts
+22
-17
No files found.
packages/next/client/index.
js
→
packages/next/client/index.
tsx
View file @
0e48ea39
This diff is collapsed.
Click to expand it.
packages/next/next-server/lib/router/router.ts
View file @
0e48ea39
...
@@ -157,16 +157,21 @@ export type PrefetchOptions = {
...
@@ -157,16 +157,21 @@ export type PrefetchOptions = {
priority
?:
boolean
priority
?:
boolean
}
}
type
RouteInfo
=
{
export
type
Private
RouteInfo
=
{
Component
:
ComponentType
Component
:
ComponentType
__N_SSG
?:
boolean
__N_SSG
?:
boolean
__N_SSP
?:
boolean
__N_SSP
?:
boolean
props
?:
any
props
?:
Record
<
string
,
any
>
err
?:
Error
err
?:
Error
error
?:
any
error
?:
any
}
}
type
Subscription
=
(
data
:
RouteInfo
,
App
?:
ComponentType
)
=>
Promise
<
void
>
export
type
AppProps
=
Pick
<
PrivateRouteInfo
,
'Component'
|
'err'
>
&
{
router
:
Router
}
&
Record
<
string
,
any
>
export
type
AppComponent
=
ComponentType
<
AppProps
>
type
Subscription
=
(
data
:
PrivateRouteInfo
,
App
:
AppComponent
)
=>
Promise
<
void
>
type
BeforePopStateCallback
=
(
state
:
NextHistoryState
)
=>
boolean
type
BeforePopStateCallback
=
(
state
:
NextHistoryState
)
=>
boolean
...
@@ -227,7 +232,7 @@ export default class Router implements BaseRouter {
...
@@ -227,7 +232,7 @@ export default class Router implements BaseRouter {
/**
/**
* Map of all components loaded in `Router`
* Map of all components loaded in `Router`
*/
*/
components
:
{
[
pathname
:
string
]:
RouteInfo
}
components
:
{
[
pathname
:
string
]:
Private
RouteInfo
}
// Static Data Cache
// Static Data Cache
sdc
:
{
[
asPath
:
string
]:
object
}
=
{}
sdc
:
{
[
asPath
:
string
]:
object
}
=
{}
sub
:
Subscription
sub
:
Subscription
...
@@ -235,7 +240,7 @@ export default class Router implements BaseRouter {
...
@@ -235,7 +240,7 @@ export default class Router implements BaseRouter {
pageLoader
:
any
pageLoader
:
any
_bps
:
BeforePopStateCallback
|
undefined
_bps
:
BeforePopStateCallback
|
undefined
events
:
MittEmitter
events
:
MittEmitter
_wrapApp
:
(
App
:
ComponentType
)
=>
any
_wrapApp
:
(
App
:
AppComponent
)
=>
any
isSsr
:
boolean
isSsr
:
boolean
isFallback
:
boolean
isFallback
:
boolean
_inFlightRoute
?:
string
_inFlightRoute
?:
string
...
@@ -260,8 +265,8 @@ export default class Router implements BaseRouter {
...
@@ -260,8 +265,8 @@ export default class Router implements BaseRouter {
initialProps
:
any
initialProps
:
any
pageLoader
:
any
pageLoader
:
any
Component
:
ComponentType
Component
:
ComponentType
App
:
ComponentType
App
:
AppComponent
wrapApp
:
(
App
:
ComponentType
)
=>
any
wrapApp
:
(
App
:
AppComponent
)
=>
any
err
?:
Error
err
?:
Error
isFallback
:
boolean
isFallback
:
boolean
}
}
...
@@ -284,7 +289,7 @@ export default class Router implements BaseRouter {
...
@@ -284,7 +289,7 @@ export default class Router implements BaseRouter {
}
}
}
}
this
.
components
[
'/_app'
]
=
{
Component
:
App
}
this
.
components
[
'/_app'
]
=
{
Component
:
App
as
ComponentType
}
// Backwards compat for Router.router.events
// Backwards compat for Router.router.events
// TODO: Should be remove the following major version as it was never documented
// TODO: Should be remove the following major version as it was never documented
...
@@ -640,7 +645,7 @@ export default class Router implements BaseRouter {
...
@@ -640,7 +645,7 @@ export default class Router implements BaseRouter {
query
:
ParsedUrlQuery
,
query
:
ParsedUrlQuery
,
as
:
string
,
as
:
string
,
loadErrorFail
?:
boolean
loadErrorFail
?:
boolean
):
Promise
<
RouteInfo
>
{
):
Promise
<
Private
RouteInfo
>
{
if
(
err
.
cancelled
)
{
if
(
err
.
cancelled
)
{
// bubble up cancellation errors
// bubble up cancellation errors
throw
err
throw
err
...
@@ -664,7 +669,7 @@ export default class Router implements BaseRouter {
...
@@ -664,7 +669,7 @@ export default class Router implements BaseRouter {
try
{
try
{
const
{
page
:
Component
}
=
await
this
.
fetchComponent
(
'/_error'
)
const
{
page
:
Component
}
=
await
this
.
fetchComponent
(
'/_error'
)
const
routeInfo
:
RouteInfo
=
{
Component
,
err
,
error
:
err
}
const
routeInfo
:
Private
RouteInfo
=
{
Component
,
err
,
error
:
err
}
try
{
try
{
routeInfo
.
props
=
await
this
.
getInitialProps
(
Component
,
{
routeInfo
.
props
=
await
this
.
getInitialProps
(
Component
,
{
...
@@ -689,7 +694,7 @@ export default class Router implements BaseRouter {
...
@@ -689,7 +694,7 @@ export default class Router implements BaseRouter {
query
:
any
,
query
:
any
,
as
:
string
,
as
:
string
,
shallow
:
boolean
=
false
shallow
:
boolean
=
false
):
Promise
<
RouteInfo
>
{
):
Promise
<
Private
RouteInfo
>
{
try
{
try
{
const
cachedRouteInfo
=
this
.
components
[
route
]
const
cachedRouteInfo
=
this
.
components
[
route
]
...
@@ -697,7 +702,7 @@ export default class Router implements BaseRouter {
...
@@ -697,7 +702,7 @@ export default class Router implements BaseRouter {
return
cachedRouteInfo
return
cachedRouteInfo
}
}
const
routeInfo
:
RouteInfo
=
cachedRouteInfo
const
routeInfo
:
Private
RouteInfo
=
cachedRouteInfo
?
cachedRouteInfo
?
cachedRouteInfo
:
await
this
.
fetchComponent
(
route
).
then
((
res
)
=>
({
:
await
this
.
fetchComponent
(
route
).
then
((
res
)
=>
({
Component
:
res
.
page
,
Component
:
res
.
page
,
...
@@ -726,7 +731,7 @@ export default class Router implements BaseRouter {
...
@@ -726,7 +731,7 @@ export default class Router implements BaseRouter {
)
)
}
}
const
props
=
await
this
.
_getData
<
RouteInfo
>
(()
=>
const
props
=
await
this
.
_getData
<
Private
RouteInfo
>
(()
=>
__N_SSG
__N_SSG
?
this
.
_getStaticData
(
dataHref
!
)
?
this
.
_getStaticData
(
dataHref
!
)
:
__N_SSP
:
__N_SSP
...
@@ -754,7 +759,7 @@ export default class Router implements BaseRouter {
...
@@ -754,7 +759,7 @@ export default class Router implements BaseRouter {
pathname
:
string
,
pathname
:
string
,
query
:
ParsedUrlQuery
,
query
:
ParsedUrlQuery
,
as
:
string
,
as
:
string
,
data
:
RouteInfo
data
:
Private
RouteInfo
):
Promise
<
void
>
{
):
Promise
<
void
>
{
this
.
isFallback
=
false
this
.
isFallback
=
false
...
@@ -947,7 +952,7 @@ export default class Router implements BaseRouter {
...
@@ -947,7 +952,7 @@ export default class Router implements BaseRouter {
ctx
:
NextPageContext
ctx
:
NextPageContext
):
Promise
<
any
>
{
):
Promise
<
any
>
{
const
{
Component
:
App
}
=
this
.
components
[
'/_app'
]
const
{
Component
:
App
}
=
this
.
components
[
'/_app'
]
const
AppTree
=
this
.
_wrapApp
(
App
)
const
AppTree
=
this
.
_wrapApp
(
App
as
AppComponent
)
ctx
.
AppTree
=
AppTree
ctx
.
AppTree
=
AppTree
return
loadGetInitialProps
<
AppContextType
<
Router
>>
(
App
,
{
return
loadGetInitialProps
<
AppContextType
<
Router
>>
(
App
,
{
AppTree
,
AppTree
,
...
@@ -965,7 +970,7 @@ export default class Router implements BaseRouter {
...
@@ -965,7 +970,7 @@ export default class Router implements BaseRouter {
}
}
}
}
notify
(
data
:
RouteInfo
):
Promise
<
void
>
{
notify
(
data
:
Private
RouteInfo
):
Promise
<
void
>
{
return
this
.
sub
(
data
,
this
.
components
[
'/_app'
].
Component
)
return
this
.
sub
(
data
,
this
.
components
[
'/_app'
].
Component
as
AppComponent
)
}
}
}
}
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