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
228bbbef
Commit
228bbbef
authored
Mar 15, 2017
by
Tim Neutkens
Committed by
Arunoda Susiripala
Mar 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use jsonPageRes instead of xhr (#1424)
parent
d92ab55d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
7 deletions
+7
-7
next.js.flow
examples/with-flow/types/next.js.flow
+1
-1
error.js
lib/error.js
+2
-2
router.js
lib/router/router.js
+1
-1
readme.md
readme.md
+3
-3
No files found.
examples/with-flow/types/next.js.flow
View file @
228bbbef
...
...
@@ -42,7 +42,7 @@ declare module "next/document" {
declare export var Main: Class<React$Component<void, any, any>>;
declare export var NextScript: Class<React$Component<void, any, any>>;
declare export default Class<React$Component<void, any, any>> & {
getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any,
xhr
?: any, err?: any}) => Promise<any>;
getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any,
jsonPageRes
?: any, err?: any}) => Promise<any>;
renderPage(cb: Function): void;
};
}
lib/error.js
View file @
228bbbef
...
...
@@ -3,8 +3,8 @@ import HTTPStatus from 'http-status'
import
Head
from
'./head'
export
default
class
Error
extends
React
.
Component
{
static
getInitialProps
({
res
,
xhr
})
{
const
statusCode
=
res
?
res
.
statusCode
:
(
xhr
?
xhr
.
status
:
null
)
static
getInitialProps
({
res
,
jsonPageRes
})
{
const
statusCode
=
res
?
res
.
statusCode
:
(
jsonPageRes
?
jsonPageRes
.
status
:
null
)
return
{
statusCode
}
}
...
...
lib/router/router.js
View file @
228bbbef
...
...
@@ -341,7 +341,7 @@ export default class Router {
const
res
=
await
promise
// We need to clone this to prevent reading the body twice
// Bec
ua
se it's possible only once to read res.json() or a similar method.
// Bec
au
se it's possible only once to read res.json() or a similar method.
return
res
.
clone
()
}
...
...
readme.md
View file @
228bbbef
...
...
@@ -223,7 +223,7 @@ _Note: `getInitialProps` can **not** be used in children components. Only in `pa
-
`query`
- query string section of URL parsed as an object
-
`req`
- HTTP request object (server only)
-
`res`
- HTTP response object (server only)
-
`
xhr`
- XMLHttpRequest
object (client only)
-
`
jsonPageRes`
-
[
Fetch Response
](
https://developer.mozilla.org/en-US/docs/Web/API/Response
)
object (client only)
-
`err`
- Error object if any error is encountered during the rendering
### Routing
...
...
@@ -602,8 +602,8 @@ The `ctx` object is equivalent to the one received in all [`getInitialProps`](#f
```
jsx
import
React
from
'react'
export
default
class
Error
extends
React
.
Component
{
static
getInitialProps
({
res
,
xhr
})
{
const
statusCode
=
res
?
res
.
statusCode
:
(
xhr
?
xhr
.
status
:
null
)
static
getInitialProps
({
res
,
jsonPageRes
})
{
const
statusCode
=
res
?
res
.
statusCode
:
(
jsonPageRes
?
jsonPageRes
.
status
:
null
)
return
{
statusCode
}
}
...
...
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