Skip to content

Commit

Permalink
testing a hack
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Nov 21, 2019
1 parent 68aadc1 commit cb11765
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/gatsby/src/utils/source-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,26 @@ function getStaleNodes(state, nodes) {
})
}

let firstRun = true

/**
* Find all stale nodes and delete them
*/
function deleteStaleNodes(state, nodes) {
const staleNodes = getStaleNodes(state, nodes)

if (staleNodes.length > 0) {
staleNodes.forEach(node => deleteNode({ node }))
staleNodes.forEach(node => {
if (!firstRun && node.internal.type === `SitePage`) {
// This is a HACK!
// SitePage nodes are created in stateful way
// but we don't have sourceNodesStatefully to support
// it properly. So instead we avoid deleting them
// on non-first calls.
return
}
deleteNode({ node })
})
}
}

Expand All @@ -98,4 +110,6 @@ module.exports = async ({ webhookBody = {}, parentSpan } = {}) =>
warnForPluginsWithoutNodes(state, nodes)

deleteStaleNodes(state, nodes)

firstRun = false
})

0 comments on commit cb11765

Please sign in to comment.