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)

(cherry picked from commit 0f8d747)
  • Loading branch information
vladar authored and LekoArts committed Jul 26, 2021
1 parent 609bef1 commit c1661d4
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 c1661d4

Please sign in to comment.