If there is e.g a syntax error in the code, browser displays 500 error, then error is fixed, the console shows that code is rebuilt correctly, but the page isn't refreshed automatically (need to hit F5).
Tested with Next 1.1.0.
Hmm, I can't reproduce. Can you post steps to reproduce the problem if possible ?
OK actually the behaviour depends on where the error is thrown. For example take as a base an app which is already running (can clone my app which has next 1.1.1).
1. if I change something in a getInitialProps (e.g throw new Error() on this line), that code isn't even re-executed when HMR runs.
1b. If I then hit F5, I get a 500 page and error in server log as expected.
1c. If I then remove the throw, HMR runs but nothing happens as in 1. I need to refresh again to clear the error page.
2. if I throw an error in a render (e.g throw new Error() on this line), I will see the error in the browser log, but the rendered page won't change to an error page
2b. If I remove the throw, the browser log further displays next-dev.bundle.js:35173 TypeError: Cannot read property 'getHostNode' of null (and rendered page doesn't change either)
Maybe there are further places to test, server and browser side, constructors, etc.
- if I change something in a getInitialProps (e.g throw new Error() on this line), that code isn't even re-executed when HMR runs.
I'm not sure if we should call getInitialProps in this case, since we wouldn't like to reset props.
- if I throw an error in a render (e.g throw new Error() on this line), I will see the error in the browser log, but the rendered page won't change to an error page
This is basically because of https://github.com/facebook/react/issues/2461.
There is a workaround though https://gist.github.com/Aldredcz/4d63b0a9049b00f54439f8780be7f0d8
btw, I'm not sure if we really want to change the page to an error one in this case.
2b. If I remove the throw, the browser log further displays next-dev.bundle.js:35173 TypeError: Cannot read property 'getHostNode' of null (and rendered page doesn't change either)
I have no idea why yet.
I'm not sure if we should call getInitialProps in this case, since we wouldn't like to reset props.
It currently sounds to me like it's better to reset props and actually run the code, than to remain blind. Otherwise can't rely on HMR for quick feedback, which defeats its purpose.
btw, I'm not sure if we really want to change the page to an error one in this case.
IMHO, better to render an error page for this case too, for coherent DX.
@sedubois It's been a while since activity on the issue. Can you check if it's fixed in the latest beta build? 鉂わ笍
@timneutkens referring to my comment above https://github.com/zeit/next.js/issues/230#issuecomment-260422407:
is still present. If I add a throw new Error() in my getInitialProps and let HMR run, there isn't any error displayed. If I then refresh, error page is displayed, OK. But if I then remove the error and let HMR run, it won't clear the error page.
is fixed 馃帀
Tested with https://github.com/relatenow/relate, Next.js 2.0-beta.16
This issue has been fixed in next@canary and will be part of Next 7