diff options
author | 2024-09-13 16:08:58 -0400 | |
---|---|---|
committer | 2024-09-13 16:08:58 -0400 | |
commit | 4724b144310a88defd839f183bec927e5e3cdec0 (patch) | |
tree | b17f6d84a7013f22a04ac578f9e115a8afe4cc3e /packages/integrations/mdx/src | |
parent | bf90a5343f9cd1bb46f30e4b331e7ae675f5e720 (diff) | |
parent | 27d19f612f5627b86ca3a9de26239fd2dce32092 (diff) | |
download | astro-4724b144310a88defd839f183bec927e5e3cdec0.tar.gz astro-4724b144310a88defd839f183bec927e5e3cdec0.tar.zst astro-4724b144310a88defd839f183bec927e5e3cdec0.zip |
Merge branch 'main' into next
Diffstat (limited to 'packages/integrations/mdx/src')
-rw-r--r-- | packages/integrations/mdx/src/rehype-optimize-static.ts | 10 |
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, { |