mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.75k stars 139 forks source link

[BUG] placeholder generated a root tag pair<p></p> #391

Closed omnine closed 5 months ago

omnine commented 5 months ago

The data type of placeholder is ReactNode, which is very good, so I tried,

<MDXEditor markdown='' placeholder={(<><p>Line 1</p><p>Line 2</p></>)}/>

The Dev-Tools console reported,

Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <p>.
    at p
    at p
    at div
    at Placeholder (http://localhost:3000/static/js/bundle.js:2120:3)
    at RichTextPlugin (http://localhost:3000/static/js/bundle.js:2108:3)
    at div
    at RenderRecurisveWrappers (http://localhost:3000/static/js/bundle.js:60132:3)
    at RichTextEditor (http://localhost:3000/static/js/bundle.js:60093:164)
    at LexicalComposer (http://localhost:3000/static/js/bundle.js:1419:3)
    at LexicalProvider (http://localhost:3000/static/js/bundle.js:60076:3)
    at div
    at EditorRootElement (http://localhost:3000/static/js/bundle.js:60144:3)
    at RealmWithPlugins (http://localhost:3000/static/js/bundle.js:60250:3)
    at http://localhost:3000/static/js/bundle.js:60195:39
    at App

The html element showed,

<div class="_contentEditable_11eqz_352 _placeholder_11eqz_1034"><p><p>Line 1</p><p>Line 2</p></p></div>

petyosi commented 5 months ago

That P tag is there for a reason - otherwise if you just use a regular Hello world string (which, I believe, is what the placeholders usually look like), it will not match the styling of the editor.

While I understand how this is theoretically a "bug", fixing it is not worth it, IMO. if you insist on multiline placeholders, you can use <br />.

omnine commented 5 months ago

Then I would argue the placeholder is not a true ReactNode I am afraid.

petyosi commented 5 months ago

There's no need to argue of course. Feel free to fork and change the code to match to your requirements. I will fully refund your purchase.