decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.96k stars 3.05k forks source link

Enable React Components Rendering in Preview for MDX with Next.js #7259

Open ectuser opened 3 months ago

ectuser commented 3 months ago

Is your feature request related to a problem? Please describe.

I'm using Decap CMS, mdx format (next-mdx-remote library) in the Next.js. I need React components to render in the preview after being included in the markdown widget.

Markdown widget content:

<div>
<Navigation />
Tweet:
<Tweet id="933354946111705097" />
</div>

Here’s how it appears in a published article:

Screenshot by Dropbox Capture

And here’s how it looks in the preview:

Screenshot by Dropbox Capture

As you can see, the React components are missing in the preview, and only the text Tweet is rendered.

The published version displays the page correctly, indicating that the preview lacks the necessary configuration to render React components.

Describe the solution you'd like Adding missing configuration in public/admin/index.html, possibly including a script to render React components in the preview.

Describe alternatives you've considered

I tried CMS.registerPreviewTemplate("posts", PostPreview); and registerPreviewStyle in the index.html script, but these methods did not render React components in the markdown widget.