Skip to content

Commit

Permalink
fix(gatsby): Stopped queueing further calls to onCreatePage after a p…
Browse files Browse the repository at this point in the history
…age is deleted (#11777)

* Stopped queueing further calls to onCreatePage after a page is deleted

Co-authored-by: pieh <misiek.piechowiak@gmail.com>
  • Loading branch information
lannonbr and pieh committed Feb 20, 2019
1 parent ab12ec5 commit f32c016
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/gatsby/src/utils/api-runner-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const getCache = require(`./get-cache`)
const apiList = require(`./api-node-docs`)
const createNodeId = require(`./create-node-id`)
const createContentDigest = require(`./create-content-digest`)
const { emitter } = require(`../redux`)
const { getNonGatsbyCodeFrame } = require(`./stack-trace-utils`)

// Bind action creators per plugin so we can auto-add
Expand Down Expand Up @@ -277,7 +278,26 @@ module.exports = async (api, args = {}, pluginSource) =>
apisRunningByTraceId.set(apiRunInstance.traceId, 1)
}

let stopQueuedApiRuns = false
let onAPIRunComplete = null
if (api === `onCreatePage`) {
const path = args.page.path
const actionHandler = action => {
if (action.payload.path === path) {
stopQueuedApiRuns = true
}
}
emitter.on(`DELETE_PAGE`, actionHandler)
onAPIRunComplete = () => {
emitter.off(`DELETE_PAGE`, actionHandler)
}
}

Promise.mapSeries(noSourcePluginPlugins, plugin => {
if (stopQueuedApiRuns) {
return null
}

let pluginName =
plugin.name === `default-site-plugin`
? `gatsby-node.js`
Expand All @@ -290,6 +310,9 @@ module.exports = async (api, args = {}, pluginSource) =>
return null
})
}).then(results => {
if (onAPIRunComplete) {
onAPIRunComplete()
}
// Remove runner instance
apisRunningById.delete(apiRunInstance.id)
const currentCount = apisRunningByTraceId.get(apiRunInstance.traceId)
Expand Down

0 comments on commit f32c016

Please sign in to comment.