c9d9f1131c
* Rename getServerProps to getServerSideProps * Remove unstable_ prefix from new methods * Add error when legacy methods are detected * Add legacy methods for babel transform * Add unstable_getServerSideProps also * Apply suggestions from code review Co-Authored-By: Joe Haddad <joe.haddad@zeit.co> * Update types import Co-authored-by: Joe Haddad <timer150@gmail.com>
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { join } from 'path'
|
|
import { buildStaticPaths } from '../build/utils'
|
|
import { getPagePath } from '../next-server/server/require'
|
|
import { loadComponents } from '../next-server/server/load-components'
|
|
import { PAGES_MANIFEST, SERVER_DIRECTORY } from '../next-server/lib/constants'
|
|
|
|
// we call getStaticPaths in a separate process to ensure
|
|
// side-effects aren't relied on in dev that will break
|
|
// during a production build
|
|
export async function loadStaticPaths(
|
|
distDir: string,
|
|
buildId: string,
|
|
pathname: string,
|
|
serverless: boolean
|
|
) {
|
|
// we need to clear any modules manually here since the
|
|
// require-cache-hot-loader doesn't affect require cache here
|
|
// since we're in a separate process
|
|
delete require.cache[join(distDir, SERVER_DIRECTORY, PAGES_MANIFEST)]
|
|
|
|
const pagePath = await getPagePath(pathname, distDir, serverless, true)
|
|
delete require.cache[pagePath]
|
|
|
|
const components = await loadComponents(
|
|
distDir,
|
|
buildId,
|
|
pathname,
|
|
serverless
|
|
)
|
|
|
|
if (!components.getStaticPaths) {
|
|
// we shouldn't get to this point since the worker should
|
|
// only be called for SSG pages with getStaticPaths
|
|
throw new Error(
|
|
`Invariant: failed to load page with getStaticPaths for ${pathname}`
|
|
)
|
|
}
|
|
|
|
return buildStaticPaths(pathname, components.getStaticPaths)
|
|
}
|