Skip to content
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

Restart static paths worker after finishing task #47716

Merged
merged 3 commits into from Mar 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 41 additions & 42 deletions packages/next/src/server/dev/static-paths-worker.ts
Expand Up @@ -25,8 +25,6 @@ if (process.env.NEXT_PREBUNDLED_REACT) {
overrideBuiltInReactPackages()
}

let workerWasUsed = false

// expose AsyncLocalStorage on globalThis for react usage
const { AsyncLocalStorage } = require('async_hooks')
;(globalThis as any).AsyncLocalStorage = AsyncLocalStorage
Expand Down Expand Up @@ -69,12 +67,6 @@ export async function loadStaticPaths({
encodedPaths?: string[]
fallback?: boolean | 'blocking'
}> {
// we only want to use each worker once to prevent any invalid
// caches
if (workerWasUsed) {
process.exit(1)
}

// update work memory runtime-config
require('../../shared/lib/runtime-config').setConfig(config)
setHttpClientAndAgentOptions({
Expand All @@ -96,45 +88,52 @@ export async function loadStaticPaths({
`Invariant: failed to load page with getStaticPaths for ${pathname}`
)
}
workerWasUsed = true

if (isAppPath) {
const userland: AppRouteUserlandModule | undefined =
components.ComponentMod.routeModule?.userland
const generateParams: GenerateParams = userland
? [
{
config: {
revalidate: userland.revalidate,
dynamic: userland.dynamic,
dynamicParams: userland.dynamicParams,
try {
if (isAppPath) {
const userland: AppRouteUserlandModule | undefined =
components.ComponentMod.routeModule?.userland
const generateParams: GenerateParams = userland
? [
{
config: {
revalidate: userland.revalidate,
dynamic: userland.dynamic,
dynamicParams: userland.dynamicParams,
},
generateStaticParams: userland.generateStaticParams,
segmentPath: pathname,
},
generateStaticParams: userland.generateStaticParams,
segmentPath: pathname,
},
]
: await collectGenerateParams(components.ComponentMod.tree)
]
: await collectGenerateParams(components.ComponentMod.tree)

return await buildAppStaticPaths({
page: pathname,
generateParams,
configFileName: config.configFileName,
distDir,
requestHeaders,
incrementalCacheHandlerPath,
serverHooks,
staticGenerationAsyncStorage,
isrFlushToDisk,
fetchCacheKeyPrefix,
maxMemoryCacheSize,
})
}

return buildAppStaticPaths({
return await buildStaticPaths({
page: pathname,
generateParams,
getStaticPaths: components.getStaticPaths,
configFileName: config.configFileName,
distDir,
requestHeaders,
incrementalCacheHandlerPath,
serverHooks,
staticGenerationAsyncStorage,
isrFlushToDisk,
fetchCacheKeyPrefix,
maxMemoryCacheSize,
locales,
defaultLocale,
})
} finally {
setTimeout(() => {
// we only want to use each worker once to prevent any invalid
// caches
process.exit(1)
})
}

return buildStaticPaths({
page: pathname,
getStaticPaths: components.getStaticPaths,
configFileName: config.configFileName,
locales,
defaultLocale,
})
}