hashicorp / next-mdx-remote

Load MDX content from anywhere
Mozilla Public License 2.0
2.64k stars 140 forks source link

`details` custom component (rsc) #471

Closed abernier closed 1 month ago

abernier commented 1 month ago

Describe the bug

import { compileMDX } from "next-mdx-remote/rsc";

export default async function Page() {
  const source = `# Hello

<details>
  <summary>detail A</summary>

Just a detail

</details>`;

  const { content } = await compileMDX({
    source,
    components: {
      details(props) {
        return <details className="border-2 border-green-500" {...props} />;
      },
    },
  });

  return <main>{content}</main>;
}

=> rendered html does not have the border-2 border-green-500 class: despite the details() component

Reproduction

https://github.com/abernier/bug-next-mdx-remote-471

https://stackblitz.com/~/github.com/abernier/bug-next-mdx-remote-471?file=app/page.tsx

next-mdx-remote version

v5.0.0

abernier commented 1 month ago

just added reproduction (github + stackblitz live demo)

abernier commented 1 month ago

also tested for img:

import { compileMDX } from "next-mdx-remote/rsc";

export default async function Home() {
  const source = `# Hello

✅ It works for
---

![](https://placekitten.com/200/300)

❌ But not for
---

<img src="https://placekitten.com/200/300" alt="kitten" />

`;

  const { content } = await compileMDX({
    source,
    components: {
      img(props) {
        return (
          <img {...props} className="border-2 border-red-500" />
        );
      },
    },
  });

  return <main>{content}</main>;
}

image

talatkuyuk commented 1 month ago

It is a known behavior. The behavior is related with @mdx-js/mdx not next-mdx-remote.

All html tags (details, img etc.) you provided in a mdx are processed as html nodes. The component map is matched with only nodes derived from parsed markdown syntax other than html and jsx nodes.

abernier commented 1 month ago

thank you