Skip to content

Commit 94ce99f

Browse files
committed
Render the initial error on the server.
1 parent ab8dee2 commit 94ce99f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

server/document.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import flush from 'styled-jsx/server'
44

55
export default class Document extends Component {
66
static getInitialProps ({ renderPage }) {
7-
const {html, head} = renderPage()
7+
const { html, head, errorHtml } = renderPage()
88
const styles = flush()
9-
return { html, head, styles }
9+
return { html, head, errorHtml, styles }
1010
}
1111

1212
static childContextTypes = {
@@ -49,11 +49,11 @@ export class Main extends Component {
4949
}
5050

5151
render () {
52-
const { html } = this.context._documentProps
52+
const { html, errorHtml } = this.context._documentProps
5353
return (
5454
<div>
5555
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
56-
<div id='__next-error' />
56+
<div id='__next-error' dangerouslySetInnerHTML={{ __html: errorHtml }} />
5757
</div>
5858
)
5959
}

server/render.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Router } from '../lib/router'
99
import { loadGetInitialProps } from '../lib/utils'
1010
import Head, { defaultHead } from '../lib/head'
1111
import App from '../lib/app'
12+
import ErrorDebug from '../lib/error-debug'
1213

1314
export async function render (req, res, pathname, query, opts) {
1415
const html = await renderToHTML(req, res, pathname, opts)
@@ -67,20 +68,25 @@ async function doRender (req, res, pathname, query, {
6768
const app = createElement(App, {
6869
Component,
6970
props,
70-
err: dev ? err : null,
7171
router: new Router(pathname, query)
7272
})
7373

7474
const render = staticMarkup ? renderToStaticMarkup : renderToString
7575

7676
let html
7777
let head
78+
let errorHtml = ''
7879
try {
7980
html = render(app)
8081
} finally {
8182
head = Head.rewind() || defaultHead()
8283
}
83-
return { html, head }
84+
85+
if (err && dev) {
86+
errorHtml = render(createElement(ErrorDebug, { error: err }))
87+
}
88+
89+
return { html, head, errorHtml }
8490
}
8591

8692
const docProps = await loadGetInitialProps(Document, { ...ctx, renderPage })

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy