Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error page show twice #2964

Closed
Topthinking opened this issue Sep 18, 2017 · 2 comments
Closed

error page show twice #2964

Topthinking opened this issue Sep 18, 2017 · 2 comments

Comments

@Topthinking
Copy link

Topthinking commented Sep 18, 2017

production next build && next start

I will show the error page, so I write wrong code to show the error page and to run 'shell' . server render error and this error do not mount error component

server/render.js fn: doRender
try {
      html = render(app)
      console.log('',html)
    } finally {
      console.log('render error')
      head = Head.rewind() || defaultHead()
    }    

_error.js

import React from 'react'

class ErrorPage extends React.Component {
  static getInitialProps ({ res, jsonPageRes,err }) {
    const status = res ? res.statusCode : (jsonPageRes ? jsonPageRes.status : null)
    return { status ,err}
  }

  render() {
    console.log("catch error \r\n", this.props.err)
    return <h1>error page</h1>
  }
}

export default ErrorPage

index.js

import React from 'react'

const data = [{
  name: 'top'
}, {
  name: 'syj'
}]

const datas = data[0]

export default class Index extends React.Component {

  render() {
    return (
      <div>
        {
          datas.map(item => {
            return <span key={item.name}>{item.name}</span>
          })
        }
      </div>
    )
  }
}
 "next_run":"NODE_ENV=production next build && next start"

page show this

<div><div id="__next">
<div data-reactroot="" data-reactid="1" data-react-checksum="2060458764">
<h1 data-reactid="2">error page</h1>
</div>
</div>
<div id="__next-error">
<h1 data-reactroot="">error page</h1>
</div>
</div>

show twice

What am I supposed to do

@oliviertassinari
Copy link
Contributor

@timneutkens Thanks for taking care of this ❤️ . I can remove my hack:

-  // Only render the error message on the server.
-  // Next.js append the server side and client side version.
-  // We don't want to display both.
-  if (statusCode !== 404 && process.browser) {
-    return null
-  }

@timneutkens
Copy link
Member

@oliviertassinari 👌 🙌

@lock lock bot locked as resolved and limited conversation to collaborators May 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants