Skip to content

Commit

Permalink
Make Missing Prerender Manifest Fatal (vercel#10485)
Browse files Browse the repository at this point in the history
* Fail on Invalid Prerender Manifest

* Make Missing Prerender Manifest Fatal

* fix test
  • Loading branch information
Timer authored and chibicode committed Feb 11, 2020
1 parent 4ca0bd4 commit 5c7f719
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
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

0 comments on commit 5c7f719

Please sign in to comment.