Skip to content

Commit

Permalink
fix(gatsby): createNode return promise (#34399)
Browse files Browse the repository at this point in the history
* always return a promise from createNode

* protect against versions of gatsby that might not return a promise from createNode
  • Loading branch information
TylerBarnes authored Jan 4, 2022
1 parent 6ffe0af commit 8a9b023
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/gatsby-source-contentful/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,12 @@ export const createAssetNodes = ({
// The content of an entry is guaranteed to be updated if and only if the .sys.updatedAt field changed
assetNode.internal.contentDigest = assetItem.sys.updatedAt

createNodePromises.push(createNode(assetNode).then(() => assetNode))
// if the node hasn't changed, createNode may return `undefined` instead of a Promise on some versions of Gatsby
const maybePromise = createNode(assetNode)

createNodePromises.push(
maybePromise?.then ? maybePromise.then(() => assetNode) : assetNode
)
})

return createNodePromises
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/actions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ actions.createNode =
).find(action => action.type === `CREATE_NODE`)

if (!createNodeAction) {
return undefined
return Promise.resolve(undefined)
}

const { payload: node, traceId, parentSpan } = createNodeAction
Expand Down

0 comments on commit 8a9b023

Please sign in to comment.