Next.js: Bug in example : with-componentdidcatch

Created on 3 May 2018  路  10Comments  路  Source: vercel/next.js

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Hi,

I tried this example : with-componentdidcatch

Basically, it's using componentDidCatch in the new _app.js. It intercepts the errors and does a console.log when it intercepts one :

https://github.com/zeit/next.js/blob/02bcfb21c81bbc0f76ec8af22d4197952bd9bc15/examples/with-componentdidcatch/pages/_app.js#L3-L9

Expected Behavior

  • I see CUSTOM ERROR HANDLING in the server logs

Current Behavior

  • I don't see CUSTOM ERROR HANDLING in the logs

    • it's not in server logs

    • it's not in client logs

Steps to Reproduce (for bugs)

npx create-next-app --example with-componentdidcatch with-componentdidcatch-app
cd with-componentdidcatch-app
yarn dev

Context

The bigger picture here is trying to use error boundaries with next.js.

Your Environment

| Tech | Version |
|---------|---------|
| next | 6.0.0 |
| node | 9.8.0 |

All 10 comments

I'm adding some information about the bigger picture below.


I want to use error boundaries, but the behaviour seems very different if the page is server-side or client-side rendered :

  • on the client, the page is loaded, and the _error boundary component_ is replacing its child by the desired error message
  • on the server, the page is completely replaced by the error page, and the _error boundary component_ seems bypassed

I can build a sample github repo to show this, if it's not clear.

componentDidCatch is only supported on the client side by React, in the future i鈥檓 planning to add a hook for catching server side errors.

@timneutkens If it's not supporting server side errors, I think the example is wrong (with-componentdidcatch).

It throws an error in the rendering of the index page. There is no way to trigger this on the client-side...

@timneutkens @lucleray any news on this issue?

@timneutkens am also interested to know this.
it doesn't look like error boundaries work on client side either?
next 5.0.0
react 16.0.0

_app.js was added in Next.js 6

Thank you for speedy reply.
ok. is it the case that in 6 ErrorBounday works in both client and server or still just client?

Client-side only, this is a limitation of React itself. For server-side error reporting you can use _error.js

ok thank you.

What is this line doing?

super.componentDidCatch(error, errorInfo) 
Was this page helpful?
0 / 5 - 0 ratings