Skip to content

Commit be9773d

Browse files
committed
handle ensure rejection race condition
1 parent 06449f4 commit be9773d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/next/src/server/dev/on-demand-entry-handler.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,12 @@ export function onDemandEntryHandler({
726726
const isInsideAppDir =
727727
!!appDir && pagePathData.absolutePagePath.startsWith(appDir)
728728

729-
if (typeof isApp === 'boolean' && !(isApp === isInsideAppDir)) {
729+
if (typeof isApp === 'boolean' && isApp !== isInsideAppDir) {
730+
Error.stackTraceLimit = 15
730731
throw new Error(
731-
'Ensure bailed, found path does not match ensure type (pages/app)'
732+
`Ensure bailed, found path "${
733+
pagePathData.page
734+
}" does not match ensure type (${isApp ? 'app' : 'pages'})`
732735
)
733736
}
734737

@@ -912,7 +915,7 @@ export function onDemandEntryHandler({
912915
match?: RouteMatch
913916
isApp?: boolean
914917
}) {
915-
if (curEnsurePage.has(page)) {
918+
if (typeof isApp !== 'boolean' && curEnsurePage.has(page)) {
916919
return curEnsurePage.get(page)
917920
}
918921
const promise = ensurePageImpl({
@@ -921,7 +924,12 @@ export function onDemandEntryHandler({
921924
appPaths,
922925
match,
923926
isApp,
924-
}).finally(() => {
927+
})
928+
929+
if (typeof isApp === 'boolean') {
930+
return promise
931+
}
932+
promise.finally(() => {
925933
curEnsurePage.delete(page)
926934
})
927935
curEnsurePage.set(page, promise)

0 commit comments

Comments
 (0)