Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 853983b

Browse files
fix: fallback blocking would cause builds to crash (#139)
1 parent ae79eb0 commit 853983b

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

‎lib/helpers/isRouteWithFallback.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const getPrerenderManifest = require("./getPrerenderManifest");
33
const { dynamicRoutes } = getPrerenderManifest();
44

55
const isRouteWithFallback = (route) => {
6-
return dynamicRoutes[route] && dynamicRoutes[route].fallback;
6+
// Fallback "blocking" routes will have fallback: null in manifest
7+
return dynamicRoutes[route] && dynamicRoutes[route].fallback !== false;
78
};
89

910
module.exports = isRouteWithFallback;

‎tests/__snapshots__/defaults.test.js.snap‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ 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
22+
/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/:id.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
2023
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
2124
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
2225
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
@@ -37,6 +40,9 @@ exports[`Routing creates Netlify redirects 1`] = `
3740
/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
3841
/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
3942
/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
43+
/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
44+
/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
45+
/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
4046
/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
4147
/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
4248
/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200

‎tests/__snapshots__/i18n.test.js.snap‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ 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
24+
/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/:id.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
2225
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
2326
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
2427
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
@@ -33,6 +36,7 @@ exports[`Routing creates Netlify redirects 1`] = `
3336
/_next/data/%BUILD_ID%/es/getStaticProps/with-revalidate.json /.netlify/functions/next_getStaticProps_withrevalidate 200
3437
/_next/data/%BUILD_ID%/es/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
3538
/_next/data/%BUILD_ID%/es/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
39+
/_next/data/%BUILD_ID%/es/getStaticProps/withFallbackBlocking/:id.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
3640
/_next/data/%BUILD_ID%/es/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
3741
/_next/data/%BUILD_ID%/es/shows/:id.json /.netlify/functions/next_shows_id 200
3842
/_next/data/%BUILD_ID%/es/shows/:params/* /.netlify/functions/next_shows_params 200
@@ -42,6 +46,7 @@ exports[`Routing creates Netlify redirects 1`] = `
4246
/_next/data/%BUILD_ID%/getServerSideProps/:id.json /.netlify/functions/next_getServerSideProps_id 200
4347
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
4448
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
49+
/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/:id.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
4550
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
4651
/api/shows/:id /.netlify/functions/next_api_shows_id 200
4752
/api/shows/:params/* /.netlify/functions/next_api_shows_params 200
@@ -61,6 +66,9 @@ exports[`Routing creates Netlify redirects 1`] = `
6166
/en/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
6267
/en/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
6368
/en/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
69+
/en/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
70+
/en/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
71+
/en/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
6472
/en/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
6573
/en/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
6674
/en/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
@@ -76,6 +84,7 @@ exports[`Routing creates Netlify redirects 1`] = `
7684
/es/getStaticProps/with-revalidate /.netlify/functions/next_getStaticProps_withrevalidate 200
7785
/es/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
7886
/es/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
87+
/es/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
7988
/es/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
8089
/es/shows/:id /.netlify/functions/next_shows_id 200
8190
/es/shows/:params/* /.netlify/functions/next_shows_params 200
@@ -101,6 +110,11 @@ exports[`Routing creates Netlify redirects 1`] = `
101110
/getStaticProps/withFallback/my/path/2 /en/getStaticProps/withFallback/my/path/2 200
102111
/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
103112
/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
113+
/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
114+
/getStaticProps/withFallbackBlocking/3 /en/getStaticProps/withFallbackBlocking/3 200
115+
/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
116+
/getStaticProps/withFallbackBlocking/4 /en/getStaticProps/withFallbackBlocking/4 200
117+
/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
104118
/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
105119
/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
106120
/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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: blocking } means routes will be built when visited for the
37+
// first time and only after it's built will the client receive a response
38+
return { paths, fallback: "blocking" };
39+
}
40+
41+
export async function getStaticProps({ params }) {
42+
// The ID to render
43+
const { id } = params;
44+
45+
const res = await fetch(`https://api.tvmaze.com/shows/${id}`);
46+
const data = await res.json();
47+
48+
return {
49+
props: {
50+
show: data,
51+
},
52+
};
53+
}
54+
55+
export default Show;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /