Skip to content

Commit

Permalink
Fix MDX stack trace location with frontmatter (#11717)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Aug 16, 2024
1 parent 0109690 commit 423614e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-trees-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---

Fixes stack trace location when failed to parse an MDX file with frontmatter
5 changes: 3 additions & 2 deletions packages/integrations/mdx/src/vite-plugin-mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ export function vitePluginMdx(mdxOptions: MdxOptions): Plugin {
async transform(code, id) {
if (!id.endsWith('.mdx')) return;

const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id);
const { data: frontmatter, content: pageContent, matter } = parseFrontmatter(code, id);
const frontmatterLines = matter ? matter.match(/\n/g)?.join('') + '\n\n' : '';

const vfile = new VFile({ value: pageContent, path: id });
const vfile = new VFile({ value: frontmatterLines + pageContent, path: id });
// Ensure `data.astro` is available to all remark plugins
setVfileFrontmatter(vfile, frontmatter);

Expand Down

0 comments on commit 423614e

Please sign in to comment.