Skip to content

Commit

Permalink
exit static paths worker after finishing task
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Mar 30, 2023
1 parent b9d7732 commit ae1baae
Showing 1 changed file with 41 additions and 42 deletions.
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.userland
const generateParams: GenerateParams = userland
? [
{
config: {
revalidate: userland.revalidate,
dynamic: userland.dynamic,
dynamicParams: userland.dynamicParams,
try {
if (isAppPath) {
const userland: AppRouteUserlandModule | undefined =
components.ComponentMod.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 buildAppStaticPaths({
page: pathname,
generateParams,
configFileName: config.configFileName,
distDir,
requestHeaders,
incrementalCacheHandlerPath,
serverHooks,
staticGenerationAsyncStorage,
isrFlushToDisk,
fetchCacheKeyPrefix,
maxMemoryCacheSize,
})
}

return buildAppStaticPaths({
return 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,
})
}

0 comments on commit ae1baae

Please sign in to comment.