diff --git a/packages/gatsby/src/cache-dir/loader.js b/packages/gatsby/src/cache-dir/loader.js index 36fc8c6e17394..a4c0870566449 100644 --- a/packages/gatsby/src/cache-dir/loader.js +++ b/packages/gatsby/src/cache-dir/loader.js @@ -38,6 +38,8 @@ const sortPagesByCount = (a, b) => { } } +const prefetcher = () => {} + const queue = { empty: () => { pathArray = [] @@ -46,7 +48,6 @@ const queue = { resourcesArray = [] pages = [] }, - // Make pages injectable cause testing. addPagesArray: newPages => { pages = newPages findPage = pageFinderFactor(newPages) @@ -144,6 +145,7 @@ const queue = { console.log("need to load scripts") const page = findPage(path) console.log("for page", page) + console.log(`async requires`, asyncRequires) let component let json const done = () => { @@ -155,12 +157,19 @@ const queue = { }) } } - asyncRequires.components[page.componentChunkName](c => { - component = preferDefault(c) - done() - }) - asyncRequires.json[page.jsonName](j => { - json = preferDefault(j) + console.log(asyncRequires.components[page.componentChunkName]) + console.log(asyncRequires.json[page.jsonName]) + asyncRequires.components[page.componentChunkName]()( + callback => { + component = preferDefault(callback()) + console.log(`page component`, component) + done() + }, + () => console.log("error loading page component") + ) + asyncRequires.json[page.jsonName]()(callback => { + json = preferDefault(callback()) + console.log(`json`, json) done() }) } diff --git a/packages/gatsby/src/cache-dir/production-app.js b/packages/gatsby/src/cache-dir/production-app.js index 92508f884119f..dde6cd01e16cc 100644 --- a/packages/gatsby/src/cache-dir/production-app.js +++ b/packages/gatsby/src/cache-dir/production-app.js @@ -19,10 +19,11 @@ window.___emitter = mitt() import pages from "./pages.json" import ComponentRenderer from "./component-renderer" -import requires from "./async-requires" +import asyncRequires from "./async-requires" import loader from "./loader" loader.addPagesArray(pages) -loader.addProdRequires(requires) +loader.addProdRequires(asyncRequires) +window.asyncRequires = asyncRequires window.___loader = loader @@ -185,9 +186,9 @@ let layout // } const loadLayout = cb => { - console.log(requires) - if (requires.layouts[`index`]) { - requires.layouts[`index`](cb) + console.log(asyncRequires) + if (asyncRequires.layouts[`index`]) { + asyncRequires.layouts[`index`](cb) } else { cb(props =>
{props.children()}
) } diff --git a/packages/gatsby/src/cache-dir/static-entry.js b/packages/gatsby/src/cache-dir/static-entry.js index 8ff4f4e331217..a789d26aa0e34 100644 --- a/packages/gatsby/src/cache-dir/static-entry.js +++ b/packages/gatsby/src/cache-dir/static-entry.js @@ -1,7 +1,7 @@ import React from "react" import { renderToString, renderToStaticMarkup } from "react-dom/server" import { StaticRouter, Route, withRouter } from "react-router-dom" -import { kebabCase, get, merge, isArray } from "lodash" +import { kebabCase, get, merge, isArray, isString } from "lodash" import apiRunner from "./api-runner-ssr" import pages from "./pages.json" import syncRequires from "./sync-requires" @@ -149,19 +149,19 @@ module.exports = (locals, callback) => { if (prefixedScript === `/`) { return } + + return prefixedScript }) - .filter(s => s) + .filter(s => isString(s)) scripts.forEach(script => { // Add preload s for scripts. - headComponents.unshift( - - ) + headComponents.unshift() }) // Add script loader for page scripts to the head. // Taken from https://www.html5rocks.com/en/tutorials/speed/script-loading/ - const scriptsString = scripts.map(s => `"${prefixedScript}"`).join(`,`) + const scriptsString = scripts.map(s => `"${s}"`).join(`,`) headComponents.push(