Skip to content

Commit

Permalink
fix(gatsby): Move importing of match-paths.json outside of loader.js (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
Moocar authored and mxxk committed Jun 21, 2019
1 parent b6eb762 commit 74ee6df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import emitter from "./emitter"
import { apiRunner, apiRunnerAsync } from "./api-runner-browser"
import loader, { setApiRunnerForLoader } from "./loader"
import syncRequires from "./sync-requires"
import matchPaths from "./match-paths.json"

window.___emitter = emitter
setApiRunnerForLoader(apiRunner)
Expand Down Expand Up @@ -49,6 +50,7 @@ apiRunnerAsync(`onClientEntry`).then(() => {
)[0]

loader.addDevRequires(syncRequires)
loader.addMatchPaths(matchPaths)
Promise.all([
loader.loadPage(`/dev-404-page/`),
loader.loadPage(`/404.html`),
Expand Down
12 changes: 10 additions & 2 deletions packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import prefetchHelper from "./prefetch"
import { match } from "@reach/router/lib/utils"
import normalizePagePath from "./normalize-page-path"
import stripPrefix from "./strip-prefix"
// Generated during bootstrap
import matchPaths from "./match-paths.json"

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

Expand All @@ -13,6 +11,7 @@ const pageNotFoundPaths = new Set()
let apiRunner
let syncRequires = {}
let asyncRequires = {}
let matchPaths = {}

const fetchedPageData = {}
const pageDatas = {}
Expand Down Expand Up @@ -194,12 +193,21 @@ const loadComponent = componentChunkName => {
}

const queue = {
// gatsby-link can be used as a standalone library. Since it depends
// on window.___loader, we have to assume the code calls loader.js
// but without a gatsby build having occured. In this case,
// `async-requires.js, match-paths.json` etc won't exist. Therefore,
// we import those assets in production-app.js, and then dynamically
// set them onto the loader
addDevRequires: devRequires => {
syncRequires = devRequires
},
addProdRequires: prodRequires => {
asyncRequires = prodRequires
},
addMatchPaths: _matchPaths => {
matchPaths = _matchPaths
},
// Hovering on a link is a very strong indication the user is going to
// click on it soon so let's start prefetching resources for this
// pathname.
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby/cache-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import emitter from "./emitter"
import PageRenderer from "./page-renderer"
import asyncRequires from "./async-requires"
import matchPaths from "./match-paths.json"
import loader, { setApiRunnerForLoader } from "./loader"
import EnsureResources from "./ensure-resources"

Expand All @@ -21,6 +22,7 @@ window.___loader = loader
window.___webpackCompilationHash = window.webpackCompilationHash

loader.addProdRequires(asyncRequires)
loader.addMatchPaths(matchPaths)
setApiRunnerForLoader(apiRunner)

navigationInit()
Expand Down

0 comments on commit 74ee6df

Please sign in to comment.