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

fix: fallback blocking would cause builds to crash #139

Merged
merged 1 commit into from
Jan 10, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/helpers/isRouteWithFallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const getPrerenderManifest = require("./getPrerenderManifest");
const { dynamicRoutes } = getPrerenderManifest();

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

module.exports = isRouteWithFallback;
6 changes: 6 additions & 0 deletions tests/__snapshots__/defaults.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ exports[`Routing creates Netlify redirects 1`] = `
/_next/data/%BUILD_ID%/getStaticProps/withFallback/my/path/2.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/:id.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
Expand All @@ -37,6 +40,9 @@ exports[`Routing creates Netlify redirects 1`] = `
/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
Expand Down
14 changes: 14 additions & 0 deletions tests/__snapshots__/i18n.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ exports[`Routing creates Netlify redirects 1`] = `
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/my/path/2.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/3.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/4.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/_next/data/%BUILD_ID%/en/getStaticProps/withFallbackBlocking/:id.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/2.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
Expand All @@ -33,6 +36,7 @@ exports[`Routing creates Netlify redirects 1`] = `
/_next/data/%BUILD_ID%/es/getStaticProps/with-revalidate.json /.netlify/functions/next_getStaticProps_withrevalidate 200
/_next/data/%BUILD_ID%/es/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
/_next/data/%BUILD_ID%/es/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
/_next/data/%BUILD_ID%/es/getStaticProps/withFallbackBlocking/:id.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
/_next/data/%BUILD_ID%/es/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
/_next/data/%BUILD_ID%/es/shows/:id.json /.netlify/functions/next_shows_id 200
/_next/data/%BUILD_ID%/es/shows/:params/* /.netlify/functions/next_shows_params 200
Expand All @@ -42,6 +46,7 @@ exports[`Routing creates Netlify redirects 1`] = `
/_next/data/%BUILD_ID%/getServerSideProps/:id.json /.netlify/functions/next_getServerSideProps_id 200
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
/_next/data/%BUILD_ID%/getStaticProps/withFallbackBlocking/:id.json /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
/api/shows/:id /.netlify/functions/next_api_shows_id 200
/api/shows/:params/* /.netlify/functions/next_api_shows_params 200
Expand All @@ -61,6 +66,9 @@ exports[`Routing creates Netlify redirects 1`] = `
/en/getStaticProps/withFallback/my/path/2 /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
/en/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
/en/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
/en/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/en/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/en/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
/en/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/en/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/en/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
Expand All @@ -76,6 +84,7 @@ exports[`Routing creates Netlify redirects 1`] = `
/es/getStaticProps/with-revalidate /.netlify/functions/next_getStaticProps_withrevalidate 200
/es/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
/es/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
/es/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
/es/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
/es/shows/:id /.netlify/functions/next_shows_id 200
/es/shows/:params/* /.netlify/functions/next_shows_params 200
Expand All @@ -101,6 +110,11 @@ exports[`Routing creates Netlify redirects 1`] = `
/getStaticProps/withFallback/my/path/2 /en/getStaticProps/withFallback/my/path/2 200
/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
/getStaticProps/withFallbackBlocking/3 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/withFallbackBlocking/3 /en/getStaticProps/withFallbackBlocking/3 200
/getStaticProps/withFallbackBlocking/4 /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200! Cookie=__prerender_bypass,__next_preview_data
/getStaticProps/withFallbackBlocking/4 /en/getStaticProps/withFallbackBlocking/4 200
/getStaticProps/withFallbackBlocking/:id /.netlify/functions/next_getStaticProps_withFallbackBlocking_id 200
/getStaticProps/withRevalidate/1 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/getStaticProps/withRevalidate/2 /.netlify/functions/next_getStaticProps_withRevalidate_id 200
/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
Expand Down
55 changes: 55 additions & 0 deletions tests/fixtures/pages/getStaticProps/withFallbackBlocking/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useRouter } from "next/router";
import Link from "next/link";

const Show = ({ show }) => {
const router = useRouter();

// This is never shown on Netlify. We just need it for NextJS to be happy,
// because NextJS will render a fallback HTML page.
if (router.isFallback) {
return <div>Loading...</div>;
}

return (
<div>
<p>This page uses getStaticProps() to pre-fetch a TV show.</p>

<hr />

<h1>Show #{show.id}</h1>
<p>{show.name}</p>

<hr />

<Link href="/">
<a>Go back home</a>
</Link>
</div>
);
};

export async function getStaticPaths() {
// Set the paths we want to pre-render
const paths = [{ params: { id: "3" } }, { params: { id: "4" } }];

// We'll pre-render these paths at build time.
// { fallback: blocking } means routes will be built when visited for the
// first time and only after it's built will the client receive a response
return { paths, fallback: "blocking" };
}

export async function getStaticProps({ params }) {
// The ID to render
const { id } = params;

const res = await fetch(`https://api.tvmaze.com/shows/${id}`);
const data = await res.json();

return {
props: {
show: data,
},
};
}

export default Show;