You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Depending on where an error occurs, I've noticed at least 4 different behaviours that happen in response to an error:
I've created a minimal app with the following files: pages/_app.js, pages/_error.js, pages/[[...slug]].js and tested the following (in production build):
throw in _app.jsgetInitialProps
response on page load:Internal Server Error (string, no html document)
response on (client side) navigation: redirect/page-reload and then Internal Server Error (string, html document)
throw in _app.js render
response on page load:Internal Server Error (string, no html document)
response on (client side) navigation: exception happens client side, resulting in endless loop of react trying to render the component (browser becomes unresponsive)
throw in pages/[[...slug]].jsgetServerSideProps
response on page load: content of _error.js
response on (client side) navigation: redirect/page-reload and then content of _error.js
throw in pages/[[...slug]].js render (or any sub component)
response on page load: content of _error.js
response on (client side) navigation: content of _error.js
// pages/[[...slug]].jsimport{useRouter}from"next/router";exportdefaultfunctionRequestHandler(props){const{query}=useRouter()if(query.testerror==='page'){throw'[testerror] page';}return(<div>
Page
<pre>{JSON.stringify(props,null,4)}</pre></div>)}exportasyncfunctiongetServerSideProps({params, req, res, query, preview, previewData, resolvedUrl}){if(query.testerror==='page-getServerSideProps'){throw'[testerror] page-getServerSideProps';}if(!params.slug||['page-a','page-b'].includes(params.slug[0])){return{props: {content: `This is the ${params.slug ? params.slug[0] : 'index'} page`}}}if(!req.url.match(/^\/_next\/data\/.*slug=.*$/)){// only set status code 404 if it's a page load, not for XHR, see #18185res.statusCode=404}return{props: {myStatusCode: 404,myMessage: `couldn't find page`}}}
Example code includes Links to different URLs with exceptions
Expected behavior
exceptions in _app.js should also be caught and handled the same as in pages
exceptions in app render should not cause a rendering loop which makes the browser become unresponsive
failing the above two points, we should update the documentation to mention that there are cases where custom error handling will not work
And if the mentality is really like described in the first comment on #17574 "let it crash", then why do we have _error.js. I'm not arguing for either side, but as a project next should commit to one way and do it as consistently as possible (and clearly document cases where it's not consistent).
System information
Version of Next.js: 9.5.5
Version of Node.js: v14.12.0
The text was updated successfully, but these errors were encountered:
Bug report
Depending on where an error occurs, I've noticed at least 4 different behaviours that happen in response to an error:
I've created a minimal app with the following files:
pages/_app.js
,pages/_error.js
,pages/[[...slug]].js
and tested the following (in production build):throw
in_app.js
getInitialProps
Internal Server Error
(string, no html document)Internal Server Error
(string, html document)throw
in_app.js
renderInternal Server Error
(string, no html document)throw
inpages/[[...slug]].js
getServerSideProps
_error.js
_error.js
throw
inpages/[[...slug]].js
render (or any sub component)_error.js
_error.js
To Reproduce
Example code includes Links to different URLs with exceptions
Expected behavior
And if the mentality is really like described in the first comment on #17574 "let it crash", then why do we have
_error.js
. I'm not arguing for either side, but as a project next should commit to one way and do it as consistently as possible (and clearly document cases where it's not consistent).System information
The text was updated successfully, but these errors were encountered: