From 8a9b023510650e71f00f8c5c3d841e199f5b3ad0 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Tue, 4 Jan 2022 13:39:43 -0800 Subject: [PATCH] fix(gatsby): createNode return promise (#34399) * always return a promise from createNode * protect against versions of gatsby that might not return a promise from createNode --- packages/gatsby-source-contentful/src/normalize.js | 7 ++++++- packages/gatsby/src/redux/actions/public.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-contentful/src/normalize.js b/packages/gatsby-source-contentful/src/normalize.js index 4a82e53c0ed86..99592a7eb1549 100644 --- a/packages/gatsby-source-contentful/src/normalize.js +++ b/packages/gatsby-source-contentful/src/normalize.js @@ -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 diff --git a/packages/gatsby/src/redux/actions/public.js b/packages/gatsby/src/redux/actions/public.js index ac795f0aebb42..6053170f87974 100644 --- a/packages/gatsby/src/redux/actions/public.js +++ b/packages/gatsby/src/redux/actions/public.js @@ -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