Skip to content
Open
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 @@ -867,5 +867,6 @@
"866": "Both \"%s\" and \"%s\" files are detected. Please use \"%s\" instead.",
"867": "The %s \"%s\" must export a %s or a \\`default\\` function",
"868": "No reference found for param: %s in reference: %s",
"869": "No reference found for segment: %s with reference: %s"
"869": "No reference found for segment: %s with reference: %s",
"870": "`pipelineInSequentialTasks` should not be called in edge runtime."
}
20 changes: 0 additions & 20 deletions packages/next/src/build/templates/app-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,6 @@ export async function handler(
const nextReq = new NodeNextRequest(req)
const nextRes = new NodeNextResponse(res)

// TODO: adapt for putting the RDC inside the postponed data
// If we're in dev, and this isn't a prefetch or a server action,
// we should seed the resume data cache.
if (process.env.NODE_ENV === 'development') {
if (
nextConfig.experimental.cacheComponents &&
!isPrefetchRSCRequest &&
!context.renderOpts.isPossibleServerAction
) {
const warmup = await routeModule.warmup(nextReq, nextRes, context)

// If the warmup is successful, we should use the resume data
// cache from the warmup.
if (warmup.metadata.renderResumeDataCache) {
context.renderOpts.renderResumeDataCache =
warmup.metadata.renderResumeDataCache
}
}
}

return routeModule.render(nextReq, nextRes, context).finally(() => {
if (!span) return

Expand Down
1 change: 0 additions & 1 deletion packages/next/src/export/routes/app-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export async function exportAppPage(
fallbackRouteParams,
renderOpts,
undefined,
false,
sharedContext
)

Expand Down
37 changes: 37 additions & 0 deletions packages/next/src/server/app-render/app-render-render-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,40 @@ export function scheduleInSequentialTasks<R>(
})
}
}

/**
* This is a utility function to make scheduling sequential tasks that run back to back easier.
* We schedule on the same queue (setTimeout) at the same time to ensure no other events can sneak in between.
* The function that runs in the second task gets access to the first tasks's result.
*/
export function pipelineInSequentialTasks<A, B>(
render: () => A,
followup: (a: A) => B | Promise<B>
): Promise<B> {
if (process.env.NEXT_RUNTIME === 'edge') {
throw new InvariantError(
'`pipelineInSequentialTasks` should not be called in edge runtime.'
)
} else {
return new Promise((resolve, reject) => {
let renderResult: A | undefined = undefined
setTimeout(() => {
try {
renderResult = render()
} catch (err) {
clearTimeout(followupId)
reject(err)
}
}, 0)
const followupId = setTimeout(() => {
// if `render` threw, then the `followup` timeout would've been cleared,
// so if we got here, we're guaranteed to have a `renderResult`.
try {
resolve(followup(renderResult!))
} catch (err) {
reject(err)
}
}, 0)
})
}
}
Loading
Loading