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)
  • Loading branch information
vladar authored Jul 23, 2021
1 parent fc06a4e commit 0f8d747
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 0f8d747

Please sign in to comment.