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 :
CUSTOM ERROR HANDLING in the server logsCUSTOM ERROR HANDLING in the logsnpx create-next-app --example with-componentdidcatch with-componentdidcatch-app
cd with-componentdidcatch-app
yarn dev
The bigger picture here is trying to use error boundaries with next.js.
| Tech | Version |
|---------|---------|
| next | 6.0.0 |
| node | 9.8.0 |
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 :
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)