Skip to content

Commit

Permalink
Fix remarkMdxish performance issue on huge sites (#3572)
Browse files Browse the repository at this point in the history
  • Loading branch information
hippotastic committed Jun 10, 2022
1 parent 43dda86 commit 5c73f61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-forks-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': patch
---

Fix remarkMdxish performance issue on huge sites
13 changes: 9 additions & 4 deletions packages/markdown/remark/src/remark-mdxish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import type { Tag } from 'mdast-util-mdx-jsx';
import { mdxFromMarkdown, mdxToMarkdown } from './mdast-util-mdxish.js';
import { mdxjs } from './mdxjs.js';

export default function remarkMdxish(this: any, options = {}) {
// Prepare markdown extensions once to prevent performance issues
const extMdxJs = mdxjs({});
const extMdxFromMarkdown = makeFromMarkdownLessStrict(mdxFromMarkdown());
const extMdxToMarkdown = mdxToMarkdown();

export default function remarkMdxish(this: any) {
const data = this.data();

add('micromarkExtensions', mdxjs(options));
add('fromMarkdownExtensions', makeFromMarkdownLessStrict(mdxFromMarkdown()));
add('toMarkdownExtensions', mdxToMarkdown());
add('micromarkExtensions', extMdxJs);
add('fromMarkdownExtensions', extMdxFromMarkdown);
add('toMarkdownExtensions', extMdxToMarkdown);

function add(field: string, value: unknown) {
const list = data[field] ? data[field] : (data[field] = []);
Expand Down

0 comments on commit 5c73f61

Please sign in to comment.