Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add calling getStaticPaths in development before showing fallback
- Loading branch information
Showing
5 changed files
with
224 additions
and
152 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { loadComponents } from './load-components' | ||
import { buildStaticPaths } from '../../build/utils' | ||
// we call getStaticPaths in a separate thread 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 | ||
) { | ||
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.