@@ -443,48 +443,6 @@ export async function render(renderingProps: RenderRouteInfo): Promise<void> {
443443// `componentDidCatch`. If there's one, fallback to the simple fallback error
444444let renderErrorResolving = false
445445// FallbackError component shows when unexpected error occurs on custom _error page
446- class FallbackError < P = { } > extends React . Component < P & { err : Error } > {
447- static getInitialProps = ( { err } : { err : Error } ) => ( { err } )
448- render ( ) {
449- const { err } = this . props
450- return (
451- < div style = { fallbackErrorStyles . error } >
452- < style dangerouslySetInnerHTML = { { __html : 'body { margin: 0 }' } } />
453- < h2 >
454- { err . name }
455- { `: ` }
456- < small > { err . message } </ small >
457- </ h2 >
458- < h4 >
459- Application error: a client-side exception has occurred (
460- < a href = "https://nextjs.org/docs/messages/client-side-exception-occurred" >
461- developer guidance
462- </ a >
463- )
464- </ h4 >
465- < pre style = { fallbackErrorStyles . stack } > { err . stack } </ pre >
466- </ div >
467- )
468- }
469- }
470-
471- const fallbackErrorStyles : { [ k : string ] : React . CSSProperties } = {
472- error : {
473- color : '#000' ,
474- background : '#fff' ,
475- fontFamily :
476- '-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif' ,
477- height : '100vh' ,
478- textAlign : 'center' ,
479- display : 'flex' ,
480- flexDirection : 'column' ,
481- alignItems : 'center' ,
482- justifyContent : 'center' ,
483- } ,
484- stack : {
485- textAlign : 'left' ,
486- } ,
487- }
488446
489447// This method handles all runtime and debug errors.
490448// 404 and 500 errors are special kind of errors
@@ -512,38 +470,40 @@ export function renderError(renderErrorProps: RenderErrorProps): Promise<any> {
512470 // Make sure we log the error to the console, otherwise users can't track down issues.
513471 console . error ( err )
514472 const errorComponentPromise = renderErrorResolving
515- ? Promise . resolve ( { page : FallbackError , styleSheets : [ ] } )
473+ ? import ( '../pages/_error' ) . then ( ( m ) => ( {
474+ page : m . default ,
475+ styleSheets : [ ] ,
476+ } ) )
516477 : pageLoader . loadPage ( '/_error' )
517478
518479 renderErrorResolving = true
519- return errorComponentPromise
520- . then ( ( { page : ErrorComponent , styleSheets } ) => {
521- // In production we do a normal render with the `ErrorComponent` as component.
522- // If we've gotten here upon initial render, we can use the props from the server.
523- // Otherwise, we need to call `getInitialProps` on `App` before mounting.
524- const AppTree = wrapApp ( App )
525- const appCtx = {
480+ return errorComponentPromise . then ( ( { page : ErrorComponent , styleSheets } ) => {
481+ // In production we do a normal render with the `ErrorComponent` as component.
482+ // If we've gotten here upon initial render, we can use the props from the server.
483+ // Otherwise, we need to call `getInitialProps` on `App` before mounting.
484+ const AppTree = wrapApp ( App )
485+ const appCtx = {
486+ Component : ErrorComponent ,
487+ AppTree,
488+ router,
489+ ctx : { err, pathname : page , query, asPath, AppTree } ,
490+ }
491+ return Promise . resolve (
492+ renderErrorProps . props
493+ ? renderErrorProps . props
494+ : loadGetInitialProps ( App , appCtx )
495+ ) . then ( ( initProps ) =>
496+ doRender ( {
497+ ...renderErrorProps ,
498+ err,
526499 Component : ErrorComponent ,
527- AppTree,
528- router,
529- ctx : { err, pathname : page , query, asPath, AppTree } ,
530- }
531- return Promise . resolve (
532- renderErrorProps . props
533- ? renderErrorProps . props
534- : loadGetInitialProps ( App , appCtx )
535- ) . then ( ( initProps ) =>
536- doRender ( {
537- ...renderErrorProps ,
538- err,
539- Component : ErrorComponent ,
540- styleSheets,
541- props : initProps ,
542- } ) . then ( ( ) => {
543- renderErrorResolving = false
544- } )
545- )
546- } )
500+ styleSheets,
501+ props : initProps ,
502+ } ) . then ( ( ) => {
503+ renderErrorResolving = false
504+ } )
505+ )
506+ } )
547507}
548508
549509let reactRoot : any = null
0 commit comments