Skip to content

Commit

Permalink
fix(gatsby): resolve createNode promise when datastore is ready (#34277)
Browse files Browse the repository at this point in the history
Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
wardpeet and pieh committed Dec 17, 2021
1 parent f222c0a commit c7efdb9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/gatsby/src/redux/actions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { trueCasePathSync } = require(`true-case-path`)
const url = require(`url`)
const { slash, createContentDigest } = require(`gatsby-core-utils`)
const { hasNodeChanged } = require(`../../utils/nodes`)
const { getNode } = require(`../../datastore`)
const { getNode, getDataStore } = require(`../../datastore`)
const sanitizeNode = require(`../../utils/sanitize-node`)
const { store } = require(`../index`)
const { validatePageComponent } = require(`../../utils/validate-page-component`)
Expand Down Expand Up @@ -868,12 +868,24 @@ actions.createNode =
}

const { payload: node, traceId, parentSpan } = createNodeAction
return apiRunnerNode(`onCreateNode`, {
const maybePromise = apiRunnerNode(`onCreateNode`, {
node: wrapNode(node),
traceId,
parentSpan,
traceTags: { nodeId: node.id, nodeType: node.internal.type },
})

if (maybePromise?.then) {
return maybePromise.then(res =>
getDataStore()
.ready()
.then(() => res)
)
} else {
return getDataStore()
.ready()
.then(() => maybePromise)
}
}

const touchNodeDeprecationWarningDisplayedMessages = new Set()
Expand Down

0 comments on commit c7efdb9

Please sign in to comment.