Skip to content

Commit 7a33108

Browse files
impronunciablerauchg
authored andcommitted
Reverting default props for errors. (#12)
1 parent ea61fe4 commit 7a33108

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

Readme.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,19 @@ Each top-level component receives a `url` property with the following API:
145145

146146
```jsx
147147
import React from 'react'
148-
export default ({ statusCode }) => (
149-
<p>An error { statusCode } occurred</p>
150-
)
148+
149+
export default class Error extends React.Component {
150+
static getInitialProps ({ res, xhr }) {
151+
const statusCode = res ? res.statusCode : xhr.status
152+
return { statusCode }
153+
}
154+
155+
render () {
156+
return (
157+
<p>An error { this.props.statusCode } occurred</p>
158+
)
159+
}
160+
}
151161
```
152162

153163
### Production deployment

lib/router.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,7 @@ export default class Router {
149149
const cancel = () => { cancelled = true }
150150
this.componentLoadCancel = cancel
151151

152-
let props = {}
153-
const status = ctx.xhr.status
154-
if (status === 404 || status === 500) {
155-
props = { statusCode: ctx.xhr.status }
156-
} else {
157-
props = await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
158-
}
152+
const props = await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
159153

160154
if (cancel === this.componentLoadCancel) {
161155
this.componentLoadCancel = null

server/render.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export async function render (url, ctx = {}, {
2121
const mod = require(p)
2222
const Component = mod.default || mod
2323

24-
const { err, res } = ctx
25-
const props = ctx.err ? getErrorProps(ctx, dev) : await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
24+
const props = await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
2625
const component = await read(resolve(dir, '.next', '_bundles', 'pages', path))
2726

2827
const { html, css } = StyleSheetServer.renderStatic(() => {
@@ -63,7 +62,3 @@ export async function renderJSON (url, { dir = process.cwd() } = {}) {
6362
function getPath (url) {
6463
return parse(url || '/').pathname.slice(1).replace(/\.json$/, '')
6564
}
66-
67-
function getErrorProps (ctx, dev) {
68-
return { statusCode: ctx.res.statusCode, stacktrace: dev ? ctx.err.message : undefined }
69-
}

0 commit comments

Comments
 (0)