summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/src/rehype-optimize-static.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/mdx/src/rehype-optimize-static.ts')
-rw-r--r--packages/integrations/mdx/src/rehype-optimize-static.ts10
1 files changed, 8 insertions, 2 deletions
diff --git a/packages/integrations/mdx/src/rehype-optimize-static.ts b/packages/integrations/mdx/src/rehype-optimize-static.ts
index 80c28ab9c..eba31cae0 100644
--- a/packages/integrations/mdx/src/rehype-optimize-static.ts
+++ b/packages/integrations/mdx/src/rehype-optimize-static.ts
@@ -64,8 +64,14 @@ export const rehypeOptimizeStatic: RehypePlugin<[OptimizeOptions?]> = (options)
* A non-static node causes all its parents to be non-optimizable
*/
const isNodeNonStatic = (node: Node) => {
- // @ts-expect-error Access `.tagName` naively for perf
- return node.type.startsWith('mdx') || ignoreElementNames.has(node.tagName);
+ return (
+ node.type.startsWith('mdx') ||
+ // @ts-expect-error `node` should never have `type: 'root'`, but in some cases plugins may inject it as children,
+ // which MDX will render as a fragment instead (an MDX fragment is a `mdxJsxFlowElement` type).
+ node.type === 'root' ||
+ // @ts-expect-error Access `.tagName` naively for perf
+ ignoreElementNames.has(node.tagName)
+ );
};
visit(tree as any, {