Skip to content

Commit 228bbbe

Browse files
timneutkensarunoda
authored andcommitted
Use jsonPageRes instead of xhr (#1424)
1 parent d92ab55 commit 228bbbe

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

examples/with-flow/types/next.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ declare module "next/document" {
4242
declare export var Main: Class<React$Component<void, any, any>>;
4343
declare export var NextScript: Class<React$Component<void, any, any>>;
4444
declare export default Class<React$Component<void, any, any>> & {
45-
getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, xhr?: any, err?: any}) => Promise<any>;
45+
getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, jsonPageRes?: any, err?: any}) => Promise<any>;
4646
renderPage(cb: Function): void;
4747
};
4848
}

lib/error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import HTTPStatus from 'http-status'
33
import Head from './head'
44

55
export default class Error extends React.Component {
6-
static getInitialProps ({ res, xhr }) {
7-
const statusCode = res ? res.statusCode : (xhr ? xhr.status : null)
6+
static getInitialProps ({ res, jsonPageRes }) {
7+
const statusCode = res ? res.statusCode : (jsonPageRes ? jsonPageRes.status : null)
88
return { statusCode }
99
}
1010

lib/router/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export default class Router {
341341

342342
const res = await promise
343343
// We need to clone this to prevent reading the body twice
344-
// Becuase it's possible only once to read res.json() or a similar method.
344+
// Because it's possible only once to read res.json() or a similar method.
345345
return res.clone()
346346
}
347347

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ _Note: `getInitialProps` can **not** be used in children components. Only in `pa
223223
- `query` - query string section of URL parsed as an object
224224
- `req` - HTTP request object (server only)
225225
- `res` - HTTP response object (server only)
226-
- `xhr` - XMLHttpRequest object (client only)
226+
- `jsonPageRes` - [Fetch Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object (client only)
227227
- `err` - Error object if any error is encountered during the rendering
228228

229229
### Routing
@@ -602,8 +602,8 @@ The `ctx` object is equivalent to the one received in all [`getInitialProps`](#f
602602
```jsx
603603
import React from 'react'
604604
export default class Error extends React.Component {
605-
static getInitialProps ({ res, xhr }) {
606-
const statusCode = res ? res.statusCode : (xhr ? xhr.status : null)
605+
static getInitialProps ({ res, jsonPageRes }) {
606+
const statusCode = res ? res.statusCode : (jsonPageRes ? jsonPageRes.status : null)
607607
return { statusCode }
608608
}
609609

0 commit comments

Comments
 (0)