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

Make Missing Prerender Manifest Fatal #10485

Merged
merged 3 commits into from Feb 10, 2020
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions packages/next/build/index.ts
Expand Up @@ -801,6 +801,17 @@ export default async function build(dir: string, conf = null): Promise<void> {
dynamicRoutes: finalDynamicRoutes,
}

await fsWriteFile(
path.join(distDir, PRERENDER_MANIFEST),
JSON.stringify(prerenderManifest),
'utf8'
)
} else {
const prerenderManifest: PrerenderManifest = {
version: 1,
routes: {},
dynamicRoutes: {},
}
await fsWriteFile(
path.join(distDir, PRERENDER_MANIFEST),
JSON.stringify(prerenderManifest),
Expand Down
18 changes: 8 additions & 10 deletions packages/next/next-server/server/spr-cache.ts
@@ -1,11 +1,11 @@
import fs from 'fs'
import path from 'path'
import LRUCache from 'lru-cache'
import mkdirpOrig from 'mkdirp'
import path from 'path'
import { promisify } from 'util'
import { PrerenderManifest } from '../../build'
import { PRERENDER_MANIFEST } from '../lib/constants'
import { normalizePagePath } from './normalize-page-path'
import mkdirpOrig from 'mkdirp'

const mkdirp = promisify(mkdirpOrig)
const readFile = promisify(fs.readFile)
Expand Down Expand Up @@ -72,14 +72,12 @@ export function initializeSprCache({
!dev && (typeof flushToDisk !== 'undefined' ? flushToDisk : true),
}

try {
prerenderManifest = dev
? { routes: {}, dynamicRoutes: [] }
: JSON.parse(
fs.readFileSync(path.join(distDir, PRERENDER_MANIFEST), 'utf8')
)
} catch (_) {
prerenderManifest = { version: 1, routes: {}, dynamicRoutes: {} }
if (dev) {
prerenderManifest = { version: -1, routes: {}, dynamicRoutes: {} }
} else {
prerenderManifest = JSON.parse(
fs.readFileSync(path.join(distDir, PRERENDER_MANIFEST), 'utf8')
)
}

cache = new LRUCache({
Expand Down
22 changes: 14 additions & 8 deletions test/integration/error-in-error/pages/index.js
@@ -1,10 +1,16 @@
import Link from 'next/link'

export default () => (
<>
<h3>Hi 👋</h3>
<Link href="/a-non-existing-page">
<a>a lnik to no-where</a>
</Link>
</>
)
function Index() {
return (
<>
<h3>Hi 👋</h3>
<Link href="/a-non-existing-page">
<a>a link to no-where</a>
</Link>
</>
)
}

Index.getInitialProps = () => ({})

export default Index