Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,5 +898,6 @@
"897": "Expected HTML document to start with doctype prefix",
"898": "When using Cache Components, all `generateStaticParams` functions must return at least one result. This is to ensure that we can perform build-time validation that there is no other dynamic accesses that would cause a runtime error.\n\nLearn more: https://nextjs.org/docs/messages/empty-generate-static-params",
"899": "Both \"%s\" and \"%s\" files are detected. Please use \"%s\" instead. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy",
"900": "Both %s file \"./%s\" and %s file \"./%s\" are detected. Please use \"./%s\" only. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy"
"900": "Both %s file \"./%s\" and %s file \"./%s\" are detected. Please use \"./%s\" only. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy",
"901": "`accumulateStringChunks` received a chunk after deadline"
}
17 changes: 13 additions & 4 deletions packages/next/src/server/app-render/app-render-render-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,46 +38,55 @@ export function scheduleInSequentialTasks<R>(
export function pipelineInSequentialTasks<A, B, C>(
one: () => A,
two: (a: A) => B,
three: (b: B) => C | Promise<C>
three: (b: B) => C
): Promise<C> {
if (process.env.NEXT_RUNTIME === 'edge') {
throw new InvariantError(
'`pipelineInSequentialTasks` should not be called in edge runtime.'
)
} else {
return new Promise((resolve, reject) => {
let oneResult: A | undefined = undefined
let oneResult: A
setTimeout(() => {
try {
oneResult = one()
} catch (err) {
clearTimeout(twoId)
clearTimeout(threeId)
clearTimeout(fourId)
reject(err)
}
}, 0)

let twoResult: B | undefined = undefined
let twoResult: B
const twoId = setTimeout(() => {
// if `one` threw, then this timeout would've been cleared,
// so if we got here, we're guaranteed to have a value.
try {
twoResult = two(oneResult!)
} catch (err) {
clearTimeout(threeId)
clearTimeout(fourId)
reject(err)
}
}, 0)

let threeResult: C
const threeId = setTimeout(() => {
// if `two` threw, then this timeout would've been cleared,
// so if we got here, we're guaranteed to have a value.
try {
resolve(three(twoResult!))
threeResult = three(twoResult!)
} catch (err) {
clearTimeout(fourId)
reject(err)
}
}, 0)

// We wait a task before resolving/rejecting
const fourId = setTimeout(() => {
resolve(threeResult)
}, 0)
})
}
}
Loading