-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into error/routes-non-array
- Loading branch information
Showing
5 changed files
with
249 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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.unstable_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 unstable_getStaticPaths for ${pathname}` | ||
) | ||
} | ||
|
||
return buildStaticPaths(pathname, components.unstable_getStaticPaths) | ||
} |
Oops, something went wrong.