From a87f1bd81503bfeb6996ca38e88914cdc1c186b0 Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Mon, 2 Mar 2020 09:32:48 +0100 Subject: [PATCH] fix(gatsby): fix codepaths that result in js errors (#21829) --- packages/gatsby/cache-dir/loader.js | 4 +++- packages/gatsby/cache-dir/navigation.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/cache-dir/loader.js b/packages/gatsby/cache-dir/loader.js index 825315aa66e6a..a491264f2a80a 100644 --- a/packages/gatsby/cache-dir/loader.js +++ b/packages/gatsby/cache-dir/loader.js @@ -353,7 +353,9 @@ const createComponentUrls = componentChunkName => export class ProdLoader extends BaseLoader { constructor(asyncRequires, matchPaths) { const loadComponent = chunkName => - asyncRequires.components[chunkName]().then(preferDefault) + asyncRequires.components[chunkName] + ? asyncRequires.components[chunkName]().then(preferDefault) + : Promise.resolve() super(loadComponent, matchPaths) } diff --git a/packages/gatsby/cache-dir/navigation.js b/packages/gatsby/cache-dir/navigation.js index b80f25074f373..7d8109c78bce2 100644 --- a/packages/gatsby/cache-dir/navigation.js +++ b/packages/gatsby/cache-dir/navigation.js @@ -84,7 +84,10 @@ const navigate = (to, options = {}) => { if (!pageResources || pageResources.status === `error`) { window.history.replaceState({}, ``, location.href) window.location = pathname + clearTimeout(timeoutId) + return } + // If the loaded page has a different compilation hash to the // window, then a rebuild has occurred on the server. Reload. if (process.env.NODE_ENV === `production` && pageResources) {