From 1c75206441deb175dc2bf80abcee9f4e066597c3 Mon Sep 17 00:00:00 2001 From: "jj@jjsweb.site" Date: Wed, 17 Nov 2021 14:48:25 -0600 Subject: [PATCH] Fix unhandled rejection on route change in dev --- packages/next/client/route-loader.ts | 39 +++++++++++++--------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/next/client/route-loader.ts b/packages/next/client/route-loader.ts index 2c6b6047d7bca..7147eee9194c0 100644 --- a/packages/next/client/route-loader.ts +++ b/packages/next/client/route-loader.ts @@ -376,34 +376,30 @@ export function createRouteLoader(assetPrefix: string): RouteLoader { }, loadRoute(route: string, prefetch?: boolean) { return withFuture(route, routes, () => { - const routeFilesPromise = getFilesForRoute(assetPrefix, route) - .then(({ scripts, css }) => { - return Promise.all([ - entrypoints.has(route) - ? [] - : Promise.all(scripts.map(maybeExecuteScript)), - Promise.all(css.map(fetchStyleSheet)), - ] as const) - }) - .then((res) => { - return this.whenEntrypoint(route).then((entrypoint) => ({ - entrypoint, - styles: res[1], - })) - }) + let devBuildPromiseResolve: () => void if (process.env.NODE_ENV === 'development') { devBuildPromise = new Promise((resolve) => { - if (routeFilesPromise) { - return routeFilesPromise.finally(() => { - resolve() - }) - } + devBuildPromiseResolve = resolve }) } return resolvePromiseWithTimeout( - routeFilesPromise, + getFilesForRoute(assetPrefix, route) + .then(({ scripts, css }) => { + return Promise.all([ + entrypoints.has(route) + ? [] + : Promise.all(scripts.map(maybeExecuteScript)), + Promise.all(css.map(fetchStyleSheet)), + ] as const) + }) + .then((res) => { + return this.whenEntrypoint(route).then((entrypoint) => ({ + entrypoint, + styles: res[1], + })) + }), MS_MAX_IDLE_DELAY, markAssetError(new Error(`Route did not complete loading: ${route}`)) ) @@ -421,6 +417,7 @@ export function createRouteLoader(assetPrefix: string): RouteLoader { } return { error: err } }) + .finally(() => devBuildPromiseResolve?.()) }) }, prefetch(route: string): Promise {