Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 4a959f3

Browse files
committed
fix: fallback blocking would cause builds to crash
1 parent ae79eb0 commit 4a959f3

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

lib/pages/getStaticPropsWithFallback/pages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { dynamicRoutes } = getPrerenderManifest();
99
// Parse pages
1010
Object.entries(dynamicRoutes).forEach(([route, { dataRoute, fallback }]) => {
1111
// Skip pages without fallback
12-
if (fallback === false) return;
12+
if (!fallback) return;
1313

1414
// Add the page
1515
pages.push({

tests/__snapshots__/defaults.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ exports[`Routing creates Netlify redirects 1`] = `
1717
/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/2.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
1818
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
1919
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
20+
/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
21+
/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
2022
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
2123
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
2224
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
@@ -37,6 +39,8 @@ exports[`Routing creates Netlify redirects 1`] = `
3739
/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
3840
/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
3941
/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
42+
/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
43+
/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
4044
/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
4145
/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
4246
/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200

tests/__snapshots__/i18n.test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ exports[`Routing creates Netlify redirects 1`] = `
1919
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/my/path/2.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
2020
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
2121
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
22+
/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
23+
/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
2224
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
2325
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
2426
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
@@ -61,6 +63,8 @@ exports[`Routing creates Netlify redirects 1`] = `
6163
/en/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
6264
/en/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
6365
/en/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
66+
/en/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
67+
/en/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
6468
/en/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
6569
/en/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
6670
/en/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
@@ -101,6 +105,10 @@ exports[`Routing creates Netlify redirects 1`] = `
101105
/getStaticProps/withFallback/my/path/2 /en/getStaticProps/withFallback/my/path/2 200
102106
/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
103107
/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
108+
/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
109+
/getStaticProps/withFallbackBlocking/3 /en/getStaticProps/withFallbackBlocking/3 200
110+
/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
111+
/getStaticProps/withFallbackBlocking/4 /en/getStaticProps/withFallbackBlocking/4 200
104112
/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
105113
/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
106114
/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { useRouter } from "next/router";
2+
import Link from "next/link";
3+
4+
const Show = ({ show }) => {
5+
const router = useRouter();
6+
7+
// This is never shown on Netlify. We just need it for NextJS to be happy,
8+
// because NextJS will render a fallback HTML page.
9+
if (router.isFallback) {
10+
return <div>Loading...</div>;
11+
}
12+
13+
return (
14+
<div>
15+
<p>This page uses getStaticProps() to pre-fetch a TV show.</p>
16+
17+
<hr />
18+
19+
<h1>Show #{show.id}</h1>
20+
<p>{show.name}</p>
21+
22+
<hr />
23+
24+
<Link href="/">
25+
<a>Go back home</a>
26+
</Link>
27+
</div>
28+
);
29+
};
30+
31+
export async function getStaticPaths() {
32+
// Set the paths we want to pre-render
33+
const paths = [{ params: { id: "3" } }, { params: { id: "4" } }];
34+
35+
// We'll pre-render these paths at build time.
36+
// { fallback: true } means other routes will be rendered at runtime.
37+
return { paths, fallback: "blocking" };
38+
}
39+
40+
export async function getStaticProps({ params }) {
41+
// The ID to render
42+
const { id } = params;
43+
44+
const res = await fetch(`https://api.tvmaze.com/shows/${id}`);
45+
const data = await res.json();
46+
47+
return {
48+
props: {
49+
show: data,
50+
},
51+
};
52+
}
53+
54+
export default Show;

0 commit comments

Comments
 (0)