From 890fb367eaae649bbe981edf4baf5cf071ce97bc Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 19 Feb 2019 00:06:07 -0800 Subject: [PATCH] MORE WIP --- .../query-runner/page-query-runner.js | 13 +++++++++---- .../internal-plugins/query-runner/query-watcher.js | 9 +++++++-- packages/gatsby/src/redux/reducers/components.js | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js b/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js index 45e39fd968d23..2a21650894c34 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js +++ b/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js @@ -17,7 +17,6 @@ const { store, emitter } = require(`../../redux`) let queuedDirtyActions = [] let active = false -let running = false const runQueriesForPathnamesQueue = new Set() exports.queueQueryForPathname = pathname => { @@ -50,6 +49,7 @@ const runQueries = async () => { ...dirtyIds, ...cleanIds, ]) + console.log({ pathnamesToRun }) runQueriesForPathnamesQueue.clear() @@ -73,12 +73,13 @@ emitter.on(`CREATE_PAGE`, action => { }) const runQueuedActions = async () => { - if (active && !running) { + console.log(`runQueuedActions`, { active }) + if (active) { try { - running = true await runQueries() } finally { - running = false + // TODO what does this mean? + // Why "finally"? if (queuedDirtyActions.length > 0) { runQueuedActions() } @@ -155,6 +156,10 @@ const runQueriesForPathnames = pathnames => { let didNotQueueItems = true pageQueries.forEach(id => { const page = pages.get(id) + console.log({ + page, + component: store.getState().components.get(page.componentPath), + }) // Don't run queries for page components that haven't yet // had their queries extracted. Once that is finished, the pages // with using that component will have their queries queued again. diff --git a/packages/gatsby/src/internal-plugins/query-runner/query-watcher.js b/packages/gatsby/src/internal-plugins/query-runner/query-watcher.js index 6341d64aba2e9..041ac6d8dae9b 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/query-watcher.js +++ b/packages/gatsby/src/internal-plugins/query-runner/query-watcher.js @@ -13,7 +13,7 @@ const chokidar = require(`chokidar`) const path = require(`path`) const slash = require(`slash`) -const { store } = require(`../../redux/`) +const { store, emitter } = require(`../../redux/`) const { boundActionCreators } = require(`../../redux/actions`) const queryCompiler = require(`./query-compiler`).default const report = require(`gatsby-cli/lib/reporter`) @@ -70,11 +70,15 @@ const handlePageComponentsWithNoQueries = ({ components }, queries) => { components.forEach(c => { if (c.queryState === `QUERY_NOT_YET_EXTRACTED`) { boundActionCreators.replaceComponentQuery({ + query: ``, queryState: `QUERY_EXTRACTED`, componentPath: c.componentPath, }) + queueQueriesForPageComponent(c.componentPath) } }) + console.log({ runQueuedQueries }) + runQueuedQueries() } const handleQuery = ( @@ -145,7 +149,7 @@ const updateStateAndRunQueries = isFirstRun => { const snapshot = getQueriesSnapshot() return queryCompiler().then(queries => { handleComponentsWithRemovedQueries(snapshot, queries) - handleComponentsWithNoQueries(snapshot, queries) + handlePageComponentsWithNoQueries(snapshot, queries) let queriesWillNotRun = false queries.forEach((query, component) => { @@ -228,6 +232,7 @@ exports.extractQueries = () => { } const queueQueriesForPageComponent = componentPath => { + console.log(`queueQueriesForPageComponent`, { componentPath }) const pages = getPagesForComponent(componentPath) // Remove page data dependencies before re-running queries because // the changing of the query could have changed the data dependencies. diff --git a/packages/gatsby/src/redux/reducers/components.js b/packages/gatsby/src/redux/reducers/components.js index 7d4e7eacb4bee..4610cf114b7ed 100644 --- a/packages/gatsby/src/redux/reducers/components.js +++ b/packages/gatsby/src/redux/reducers/components.js @@ -34,9 +34,9 @@ module.exports = (state = new Map(), action) => { ) action.payload.componentPath = normalize(action.payload.componentPath) state.set(action.payload.componentPath, { - queryState: `QUERY_EXTRACTED`, ...state.get(action.payload.componentPath), query: action.payload.query, + queryState: `QUERY_EXTRACTED`, }) return state }