Commit 228bbbef authored by Tim Neutkens's avatar Tim Neutkens Committed by Arunoda Susiripala

Use jsonPageRes instead of xhr (#1424)

parent d92ab55d
...@@ -42,7 +42,7 @@ declare module "next/document" { ...@@ -42,7 +42,7 @@ declare module "next/document" {
declare export var Main: Class<React$Component<void, any, any>>; declare export var Main: Class<React$Component<void, any, any>>;
declare export var NextScript: 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>> & { 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; renderPage(cb: Function): void;
}; };
} }
...@@ -3,8 +3,8 @@ import HTTPStatus from 'http-status' ...@@ -3,8 +3,8 @@ import HTTPStatus from 'http-status'
import Head from './head' import Head from './head'
export default class Error extends React.Component { export default class Error extends React.Component {
static getInitialProps ({ res, xhr }) { static getInitialProps ({ res, jsonPageRes }) {
const statusCode = res ? res.statusCode : (xhr ? xhr.status : null) const statusCode = res ? res.statusCode : (jsonPageRes ? jsonPageRes.status : null)
return { statusCode } return { statusCode }
} }
......
...@@ -341,7 +341,7 @@ export default class Router { ...@@ -341,7 +341,7 @@ export default class Router {
const res = await promise const res = await promise
// We need to clone this to prevent reading the body twice // 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() return res.clone()
} }
......
...@@ -223,7 +223,7 @@ _Note: `getInitialProps` can **not** be used in children components. Only in `pa ...@@ -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 - `query` - query string section of URL parsed as an object
- `req` - HTTP request object (server only) - `req` - HTTP request object (server only)
- `res` - HTTP response 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 - `err` - Error object if any error is encountered during the rendering
### Routing ### Routing
...@@ -602,8 +602,8 @@ The `ctx` object is equivalent to the one received in all [`getInitialProps`](#f ...@@ -602,8 +602,8 @@ The `ctx` object is equivalent to the one received in all [`getInitialProps`](#f
```jsx ```jsx
import React from 'react' import React from 'react'
export default class Error extends React.Component { export default class Error extends React.Component {
static getInitialProps ({ res, xhr }) { static getInitialProps ({ res, jsonPageRes }) {
const statusCode = res ? res.statusCode : (xhr ? xhr.status : null) const statusCode = res ? res.statusCode : (jsonPageRes ? jsonPageRes.status : null)
return { statusCode } return { statusCode }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment