Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): generate mdx once when multiple mdx fields re…
Browse files Browse the repository at this point in the history
…quested (#32462) (#32506)

(cherry picked from commit 0f8d747)

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
  • Loading branch information
GatsbyJS Bot and vladar authored Jul 26, 2021
1 parent 609bef1 commit 4519a7c
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions packages/gatsby-plugin-mdx/gatsby/create-schema-customization.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,30 @@ module.exports = function createSchemaCustomization(
}
}

const processMDX = ({ node }) =>
genMDX({
node,
options,
store,
pathPrefix,
getNode,
getNodes,
cache,
reporter,
actions,
schema,
...helpers,
})
const pendingPromises = new WeakMap()
const processMDX = ({ node }) => {
let promise = pendingPromises.get(node)
if (!promise) {
promise = genMDX({
node,
options,
store,
pathPrefix,
getNode,
getNodes,
cache,
reporter,
actions,
schema,
...helpers,
})
pendingPromises.set(node, promise)
promise.then(() => {
pendingPromises.delete(node)
})
}
return promise
}

// New Code // Schema
const MdxType = schema.buildObjectType({
Expand Down

0 comments on commit 4519a7c

Please # to comment.