diff --git a/examples/with-flow/types/next.js.flow b/examples/with-flow/types/next.js.flow index be09cef821f4..2a07bcb95cfe 100644 --- a/examples/with-flow/types/next.js.flow +++ b/examples/with-flow/types/next.js.flow @@ -42,7 +42,7 @@ declare module "next/document" { declare export var Main: Class>; declare export var NextScript: Class>; declare export default Class> & { - getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, xhr?: any, err?: any}) => Promise; + getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, jsonPageRes?: any, err?: any}) => Promise; renderPage(cb: Function): void; }; } diff --git a/lib/error.js b/lib/error.js index cef4d7869d59..1b4890836d50 100644 --- a/lib/error.js +++ b/lib/error.js @@ -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 } } diff --git a/lib/router/router.js b/lib/router/router.js index 01b3e2856bf2..2c46e3ff1213 100644 --- a/lib/router/router.js +++ b/lib/router/router.js @@ -341,7 +341,7 @@ export default class Router { const res = await promise // We need to clone this to prevent reading the body twice - // Becuase it's possible only once to read res.json() or a similar method. + // Because it's possible only once to read res.json() or a similar method. return res.clone() } diff --git a/readme.md b/readme.md index 4127feaedadf..f21f05180e68 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -592,8 +592,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 } }