Skip to content

Commit 672e384

Browse files
Moocarwardpeet
authored andcommitted
fix(gatsby): Move importing of match-paths.json outside of loader.js (#14732)
1 parent e5171f1 commit 672e384

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/gatsby/cache-dir/app.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import emitter from "./emitter"
77
import { apiRunner, apiRunnerAsync } from "./api-runner-browser"
88
import loader, { setApiRunnerForLoader } from "./loader"
99
import syncRequires from "./sync-requires"
10+
import matchPaths from "./match-paths.json"
1011

1112
window.___emitter = emitter
1213
setApiRunnerForLoader(apiRunner)
@@ -49,6 +50,7 @@ apiRunnerAsync(`onClientEntry`).then(() => {
4950
)[0]
5051

5152
loader.addDevRequires(syncRequires)
53+
loader.addMatchPaths(matchPaths)
5254
Promise.all([
5355
loader.loadPage(`/dev-404-page/`),
5456
loader.loadPage(`/404.html`),

packages/gatsby/cache-dir/loader.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import prefetchHelper from "./prefetch"
33
import { match } from "@reach/router/lib/utils"
44
import normalizePagePath from "./normalize-page-path"
55
import stripPrefix from "./strip-prefix"
6-
// Generated during bootstrap
7-
import matchPaths from "./match-paths.json"
86

97
const preferDefault = m => (m && m.default) || m
108

@@ -13,6 +11,7 @@ const pageNotFoundPaths = new Set()
1311
let apiRunner
1412
let syncRequires = {}
1513
let asyncRequires = {}
14+
let matchPaths = {}
1615

1716
const fetchedPageData = {}
1817
const pageDatas = {}
@@ -194,12 +193,21 @@ const loadComponent = componentChunkName => {
194193
}
195194

196195
const queue = {
196+
// gatsby-link can be used as a standalone library. Since it depends
197+
// on window.___loader, we have to assume the code calls loader.js
198+
// but without a gatsby build having occured. In this case,
199+
// `async-requires.js, match-paths.json` etc won't exist. Therefore,
200+
// we import those assets in production-app.js, and then dynamically
201+
// set them onto the loader
197202
addDevRequires: devRequires => {
198203
syncRequires = devRequires
199204
},
200205
addProdRequires: prodRequires => {
201206
asyncRequires = prodRequires
202207
},
208+
addMatchPaths: _matchPaths => {
209+
matchPaths = _matchPaths
210+
},
203211
// Hovering on a link is a very strong indication the user is going to
204212
// click on it soon so let's start prefetching resources for this
205213
// pathname.

packages/gatsby/cache-dir/production-app.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import emitter from "./emitter"
1313
import PageRenderer from "./page-renderer"
1414
import asyncRequires from "./async-requires"
15+
import matchPaths from "./match-paths.json"
1516
import loader, { setApiRunnerForLoader } from "./loader"
1617
import EnsureResources from "./ensure-resources"
1718

@@ -21,6 +22,7 @@ window.___loader = loader
2122
window.___webpackCompilationHash = window.webpackCompilationHash
2223

2324
loader.addProdRequires(asyncRequires)
25+
loader.addMatchPaths(matchPaths)
2426
setApiRunnerForLoader(apiRunner)
2527

2628
navigationInit()

0 commit comments

Comments
 (0)