Unverified Commit 36d3198e authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix unhandled rejection on route change in dev (#31554)

This ensures we properly catch the rejection on route change failure in development so the dev overlay doesn't flash with the unhandled rejection. A test case isn't able to be added for this specific scenario as the unhandled rejection is fired right before the page is navigated so we can't consistently check if the rejection was unhandled or not. 

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/28560
parent 44b4dbcd
...@@ -376,34 +376,30 @@ export function createRouteLoader(assetPrefix: string): RouteLoader { ...@@ -376,34 +376,30 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
}, },
loadRoute(route: string, prefetch?: boolean) { loadRoute(route: string, prefetch?: boolean) {
return withFuture<RouteLoaderEntry>(route, routes, () => { return withFuture<RouteLoaderEntry>(route, routes, () => {
const routeFilesPromise = getFilesForRoute(assetPrefix, route) let devBuildPromiseResolve: () => void
.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],
}))
})
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
devBuildPromise = new Promise<void>((resolve) => { devBuildPromise = new Promise<void>((resolve) => {
if (routeFilesPromise) { devBuildPromiseResolve = resolve
return routeFilesPromise.finally(() => {
resolve()
})
}
}) })
} }
return resolvePromiseWithTimeout( 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, MS_MAX_IDLE_DELAY,
markAssetError(new Error(`Route did not complete loading: ${route}`)) markAssetError(new Error(`Route did not complete loading: ${route}`))
) )
...@@ -421,6 +417,7 @@ export function createRouteLoader(assetPrefix: string): RouteLoader { ...@@ -421,6 +417,7 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
} }
return { error: err } return { error: err }
}) })
.finally(() => devBuildPromiseResolve?.())
}) })
}, },
prefetch(route: string): Promise<void> { prefetch(route: string): Promise<void> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment