Skip to content

Commit dbf35a7

Browse files
authored
Fix build restart log (#56543)
### Observed Issue ``` ⚠ Restarted collecting page data for [object Object] because it took more than 60 seconds ``` ### Fix The original issue is caused because the path is assigned to the `argument` array itself. Passing the argument type to the he worker, so in restart callback we're type safe, can the value will be correct.
1 parent c60ecfc commit dbf35a7

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

packages/next/src/build/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import type { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
44
import type { ExportPathMap, NextConfigComplete } from '../server/config-shared'
55
import type { MiddlewareManifest } from './webpack/plugins/middleware-plugin'
66
import type { ActionManifest } from './webpack/plugins/flight-client-entry-plugin'
7-
import type { ExportAppOptions, ExportAppWorker } from '../export/types'
7+
import type {
8+
ExportAppOptions,
9+
ExportAppWorker,
10+
ExportPageInput,
11+
} from '../export/types'
812

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

@@ -1211,12 +1215,13 @@ export default async function build(
12111215
| 'isPageStatic'
12121216
| 'getDefinedNamedExports'
12131217
| 'exportPage'
1214-
>
1218+
>,
1219+
[ExportPageInput]
12151220
>(staticWorkerPath, {
12161221
timeout: timeout * 1000,
12171222
onRestart: (method, [arg], attempts) => {
12181223
if (method === 'exportPage') {
1219-
const { path: pagePath } = arg
1224+
const pagePath = arg.path
12201225
if (attempts >= 3) {
12211226
throw new Error(
12221227
`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`
@@ -1226,7 +1231,7 @@ export default async function build(
12261231
`Restarted static page generation for ${pagePath} because it took more than ${timeout} seconds`
12271232
)
12281233
} else {
1229-
const pagePath = arg
1234+
const pagePath = arg.path
12301235
if (attempts >= 2) {
12311236
throw new Error(
12321237
`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`

packages/next/src/export/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
ExportAppOptions,
44
ExportWorker,
55
WorkerRenderOptsPartial,
6+
ExportPageInput,
67
} from './types'
78
import type { PrerenderManifest } from '../build'
89
import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
@@ -173,7 +174,7 @@ function setupWorkers(
173174

174175
let infoPrinted = false
175176

176-
const worker = Worker.create<typeof import('./worker')>(
177+
const worker = Worker.create<typeof import('./worker'), [ExportPageInput]>(
177178
require.resolve('./worker'),
178179
{
179180
timeout: timeout * 1000,

packages/next/src/lib/worker.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,31 @@ const cleanupWorkers = (worker: JestWorker) => {
1717
}
1818
}
1919

20-
type Options<T extends object = object> = FarmOptions & {
20+
type Options<
21+
T extends object = object,
22+
Args extends any[] = any[]
23+
> = FarmOptions & {
2124
timeout?: number
22-
onRestart?: (method: string, args: any[], attempts: number) => void
25+
onRestart?: (method: string, args: Args, attempts: number) => void
2326
exposedMethods: ReadonlyArray<keyof T>
2427
enableWorkerThreads?: boolean
2528
}
2629

27-
export class Worker<T extends object = object> {
30+
export class Worker<T extends object = object, Args extends any[] = any[]> {
2831
private _worker?: JestWorker
2932

3033
/**
3134
* Creates a new worker with the correct typings associated with the selected
3235
* methods.
3336
*/
34-
public static create<T extends object>(
37+
public static create<T extends object, Args extends any[] = any[]>(
3538
workerPath: string,
36-
options: Options<T>
37-
): Worker<T> & T {
38-
return new Worker(workerPath, options) as Worker<T> & T
39+
options: Options<T, Args>
40+
): Worker<T, Args> & T {
41+
return new Worker(workerPath, options) as Worker<T, Args> & T
3942
}
4043

41-
constructor(workerPath: string, options: Options<T>) {
44+
constructor(workerPath: string, options: Options<T, Args>) {
4245
let { timeout, onRestart, ...farmOptions } = options
4346

4447
let restartPromise: Promise<typeof RESTARTED>
@@ -133,7 +136,7 @@ export class Worker<T extends object = object> {
133136
<M extends (...args: unknown[]) => Promise<unknown> | unknown>(
134137
method: M
135138
) =>
136-
async (...args: Parameters<M>) => {
139+
async (...args: Args) => {
137140
activeTasks++
138141

139142
try {

0 commit comments

Comments
 (0)