Skip to content

Commit 0f8d747

Browse files
authored
fix(gatsby-plugin-mdx): generate mdx once when multiple mdx fields requested (#32462)
1 parent fc06a4e commit 0f8d747

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

packages/gatsby-plugin-mdx/gatsby/create-schema-customization.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,30 @@ module.exports = function createSchemaCustomization(
9393
}
9494
}
9595

96-
const processMDX = ({ node }) =>
97-
genMDX({
98-
node,
99-
options,
100-
store,
101-
pathPrefix,
102-
getNode,
103-
getNodes,
104-
cache,
105-
reporter,
106-
actions,
107-
schema,
108-
...helpers,
109-
})
96+
const pendingPromises = new WeakMap()
97+
const processMDX = ({ node }) => {
98+
let promise = pendingPromises.get(node)
99+
if (!promise) {
100+
promise = genMDX({
101+
node,
102+
options,
103+
store,
104+
pathPrefix,
105+
getNode,
106+
getNodes,
107+
cache,
108+
reporter,
109+
actions,
110+
schema,
111+
...helpers,
112+
})
113+
pendingPromises.set(node, promise)
114+
promise.then(() => {
115+
pendingPromises.delete(node)
116+
})
117+
}
118+
return promise
119+
}
110120

111121
// New Code // Schema
112122
const MdxType = schema.buildObjectType({

0 commit comments

Comments
 (0)