@@ -439,11 +439,6 @@ export async function render(renderingProps: RenderRouteInfo): Promise<void> {
439439 }
440440}
441441
442- // This indicator is used to detect if loop occurs between `renderError` and
443- // `componentDidCatch`. If there's one, fallback to the simple fallback error
444- let renderErrorResolving = false
445- // FallbackError component shows when unexpected error occurs on custom _error page
446-
447442// This method handles all runtime and debug errors.
448443// 404 and 500 errors are special kind of errors
449444// and they are still handle via the main render method.
@@ -469,41 +464,41 @@ export function renderError(renderErrorProps: RenderErrorProps): Promise<any> {
469464
470465 // Make sure we log the error to the console, otherwise users can't track down issues.
471466 console . error ( err )
472- const errorComponentPromise = renderErrorResolving
473- ? import ( '../pages/_error' ) . then ( ( m ) => ( {
474- page : m . default ,
475- styleSheets : [ ] ,
476- } ) )
477- : pageLoader . loadPage ( '/_error' )
478-
479- renderErrorResolving = true
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,
467+ return pageLoader
468+ . loadPage ( '/_error' )
469+ . then ( ( { page : ErrorComponent , styleSheets } ) => {
470+ return lastAppProps ?. Component === ErrorComponent
471+ ? import ( '../pages/_error' ) . then ( ( m ) => ( {
472+ page : m . default as React . ComponentType < { } > ,
473+ styleSheets : [ ] ,
474+ } ) )
475+ : { page : ErrorComponent , styleSheets }
476+ } )
477+ . then ( ( { page : ErrorComponent , styleSheets } ) => {
478+ // In production we do a normal render with the `ErrorComponent` as component.
479+ // If we've gotten here upon initial render, we can use the props from the server.
480+ // Otherwise, we need to call `getInitialProps` on `App` before mounting.
481+ const AppTree = wrapApp ( App )
482+ const appCtx = {
499483 Component : ErrorComponent ,
500- styleSheets,
501- props : initProps ,
502- } ) . then ( ( ) => {
503- renderErrorResolving = false
504- } )
505- )
506- } )
484+ AppTree,
485+ router,
486+ ctx : { err, pathname : page , query, asPath, AppTree } ,
487+ }
488+ return Promise . resolve (
489+ renderErrorProps . props
490+ ? renderErrorProps . props
491+ : loadGetInitialProps ( App , appCtx )
492+ ) . then ( ( initProps ) =>
493+ doRender ( {
494+ ...renderErrorProps ,
495+ err,
496+ Component : ErrorComponent ,
497+ styleSheets,
498+ props : initProps ,
499+ } )
500+ )
501+ } )
507502}
508503
509504let reactRoot : any = null
0 commit comments