Skip to content

Commit 7b40ffa

Browse files
authored
Add handling for app/pages manifest race condition (#45244)
1 parent 5ca8bd9 commit 7b40ffa

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/next/src/server/load-components.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ export async function loadDefaultErrorComponents(distDir: string) {
6262
}
6363
}
6464

65+
async function loadManifest<T>(manifestPath: string, attempts = 1): Promise<T> {
66+
try {
67+
return require(manifestPath)
68+
} catch (err) {
69+
if (attempts >= 3) {
70+
throw err
71+
}
72+
await new Promise((resolve) => setTimeout(resolve, 100))
73+
return loadManifest(manifestPath, attempts + 1)
74+
}
75+
}
76+
6577
export async function loadComponents({
6678
distDir,
6779
pathname,
@@ -87,10 +99,12 @@ export async function loadComponents({
8799

88100
const [buildManifest, reactLoadableManifest, serverComponentManifest] =
89101
await Promise.all([
90-
require(join(distDir, BUILD_MANIFEST)),
91-
require(join(distDir, REACT_LOADABLE_MANIFEST)),
102+
loadManifest<BuildManifest>(join(distDir, BUILD_MANIFEST)),
103+
loadManifest<ReactLoadableManifest>(
104+
join(distDir, REACT_LOADABLE_MANIFEST)
105+
),
92106
hasServerComponents
93-
? require(join(distDir, 'server', FLIGHT_MANIFEST + '.json'))
107+
? loadManifest(join(distDir, 'server', FLIGHT_MANIFEST + '.json'))
94108
: null,
95109
])
96110

0 commit comments

Comments
 (0)