Skip to content

Commit

Permalink
handle ensure rejection race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Sep 18, 2023
1 parent 06449f4 commit be9773d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/next/src/server/dev/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,12 @@ export function onDemandEntryHandler({
const isInsideAppDir =
!!appDir && pagePathData.absolutePagePath.startsWith(appDir)

if (typeof isApp === 'boolean' && !(isApp === isInsideAppDir)) {
if (typeof isApp === 'boolean' && isApp !== isInsideAppDir) {
Error.stackTraceLimit = 15
throw new Error(
'Ensure bailed, found path does not match ensure type (pages/app)'
`Ensure bailed, found path "${
pagePathData.page
}" does not match ensure type (${isApp ? 'app' : 'pages'})`
)
}

Expand Down Expand Up @@ -912,7 +915,7 @@ export function onDemandEntryHandler({
match?: RouteMatch
isApp?: boolean
}) {
if (curEnsurePage.has(page)) {
if (typeof isApp !== 'boolean' && curEnsurePage.has(page)) {
return curEnsurePage.get(page)
}
const promise = ensurePageImpl({
Expand All @@ -921,7 +924,12 @@ export function onDemandEntryHandler({
appPaths,
match,
isApp,
}).finally(() => {
})

if (typeof isApp === 'boolean') {
return promise
}
promise.finally(() => {
curEnsurePage.delete(page)
})
curEnsurePage.set(page, promise)
Expand Down

0 comments on commit be9773d

Please sign in to comment.