Skip to content
Merged
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
4 changes: 3 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -872,5 +872,7 @@
"871": "Image with src \"%s\" is using a query string which is not configured in images.localPatterns.\\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns",
"872": "updateTag can only be called from within a Server Action. To invalidate cache tags in Route Handlers or other contexts, use revalidateTag instead. See more info here: https://nextjs.org/docs/app/api-reference/functions/updateTag",
"873": "Invalid profile provided \"%s\" must be configured under cacheLife in next.config or be \"max\"",
"874": "Expected not to install Node.js global behaviors in the edge runtime."
"874": "Expected not to install Node.js global behaviors in the edge runtime.",
"875": "`pipelineInSequentialTasks` should not be called in edge runtime.",
"876": "dynamicInDevStagedRendering should only be used in development mode and when Cache Components is enabled."
}
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