Skip to content

Fix build restart log #56543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 7, 2023
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
13 changes: 9 additions & 4 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import type { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
import type { ExportPathMap, NextConfigComplete } from '../server/config-shared'
import type { MiddlewareManifest } from './webpack/plugins/middleware-plugin'
import type { ActionManifest } from './webpack/plugins/flight-client-entry-plugin'
import type { ExportAppOptions, ExportAppWorker } from '../export/types'
import type {
ExportAppOptions,
ExportAppWorker,
ExportPageInput,
} from '../export/types'

import '../lib/setup-exception-listeners'

Expand Down Expand Up @@ -1211,12 +1215,13 @@ export default async function build(
| 'isPageStatic'
| 'getDefinedNamedExports'
| 'exportPage'
>
>,
[ExportPageInput]
>(staticWorkerPath, {
timeout: timeout * 1000,
onRestart: (method, [arg], attempts) => {
if (method === 'exportPage') {
const { path: pagePath } = arg
const pagePath = arg.path
if (attempts >= 3) {
throw new Error(
`Static page generation for ${pagePath} is still timing out after 3 attempts. See more info here https://nextjs.org/docs/messages/static-page-generation-timeout`
Expand All @@ -1226,7 +1231,7 @@ export default async function build(
`Restarted static page generation for ${pagePath} because it took more than ${timeout} seconds`
)
} else {
const pagePath = arg
const pagePath = arg.path
if (attempts >= 2) {
throw new Error(
`Collecting page data for ${pagePath} is still timing out after 2 attempts. See more info here https://nextjs.org/docs/messages/page-data-collection-timeout`
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ExportAppOptions,
ExportWorker,
WorkerRenderOptsPartial,
ExportPageInput,
} from './types'
import type { PrerenderManifest } from '../build'
import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
Expand Down Expand Up @@ -173,7 +174,7 @@ function setupWorkers(

let infoPrinted = false

const worker = Worker.create<typeof import('./worker')>(
const worker = Worker.create<typeof import('./worker'), [ExportPageInput]>(
require.resolve('./worker'),
{
timeout: timeout * 1000,
Expand Down
21 changes: 12 additions & 9 deletions packages/next/src/lib/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,31 @@ const cleanupWorkers = (worker: JestWorker) => {
}
}

type Options<T extends object = object> = FarmOptions & {
type Options<
T extends object = object,
Args extends any[] = any[]
> = FarmOptions & {
timeout?: number
onRestart?: (method: string, args: any[], attempts: number) => void
onRestart?: (method: string, args: Args, attempts: number) => void
exposedMethods: ReadonlyArray<keyof T>
enableWorkerThreads?: boolean
}

export class Worker<T extends object = object> {
export class Worker<T extends object = object, Args extends any[] = any[]> {
private _worker?: JestWorker

/**
* Creates a new worker with the correct typings associated with the selected
* methods.
*/
public static create<T extends object>(
public static create<T extends object, Args extends any[] = any[]>(
workerPath: string,
options: Options<T>
): Worker<T> & T {
return new Worker(workerPath, options) as Worker<T> & T
options: Options<T, Args>
): Worker<T, Args> & T {
return new Worker(workerPath, options) as Worker<T, Args> & T
}

constructor(workerPath: string, options: Options<T>) {
constructor(workerPath: string, options: Options<T, Args>) {
let { timeout, onRestart, ...farmOptions } = options

let restartPromise: Promise<typeof RESTARTED>
Expand Down Expand Up @@ -133,7 +136,7 @@ export class Worker<T extends object = object> {
<M extends (...args: unknown[]) => Promise<unknown> | unknown>(
method: M
) =>
async (...args: Parameters<M>) => {
async (...args: Args) => {
activeTasks++

try {
Expand Down