You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched issues and couldn’t find anything (or linked relevant results below)
Problem
Typically a className prop in React adds a class name to the element it creates. For react-markdown this is not the case. Instead, it creates a wrapper that gets the class name. This is a fairly useless feature, because the user can wrap the content in a wrapper component themselves. That even gives the user more control.
In other words, these two are equivalent:
importMarkdownfrom'react-markdown'exportfunctionComponent({ children }){return(<MarkdownclassName="some-class">{children}</Markdown>)}
importMarkdownfrom'react-markdown'exportfunctionComponent({ children }){return(<divclassName="some-class"><Markdown>{children}</Markdown></div>)}
Solution
Deprecate the className prop, and remove it in then next semver major release.
a) is it really worth the churn to remove a nice to have feature that isn’t super useful but well, folks might want, and also people will already have, do we really need to break peoples code
b) we always generate a block. Generating a div around blocks is fine, doesn’t cause a shift.
Sure it’s quite useless. But it isn’t bad?
One more alternative: accept all IntrinsicAttributes['div'] too.
I would flip the question: If we didn’t support the className prop yet, would it be worth adding it, if it requires doing something unexpected (adding a wrapper element)?
This behaviour is documented, but typically a className prop forwards it to the top-level component, not insert one additionally.
The alternative of having the user wrap <Markdown /> inside a <div /> manually is much more flexible. They can add any props they want to the <div />, or even use an entirely different element.
I don’t think we should remove of right away, but I think it would be nice to remove in a next major version.
I’m not really opposed. But I feel like the churn/discussions/etc just doesn’t matter much. There’s a lot to maintain. Feel free to PR a comment: // To do: deprecate next major.
I'm of a similar mind to @remcohaszing, I see a mapping of className or other <div> related props as muddling the top level API.
Users adding their own wrapper is more flexible and clear.
I'd lean against adding even more <div> props before a release removing support.
We want to minimize the amount of attributes users will need to change, not add more.
The problem with adding more props is, how far do you want to go? <div> supports tens (hundreds? Infinity including data-*?) of props. Why <div>, and not <main>, or a custom component? Should there be an as prop?
All of these choices complicate the API. Also there was simply no other way before the introduction of fragments / returning arrays. Removing the prop and promoting composition simplifies it.
All props can be supported via simple {...props}, and for the tag name, div vs main doesn't change anything, it's just a choice. Or even it can be supported to be changed while I don't think it makes any sense.
Or even the user can use React.cloneElement easily if they really want to hack.
Actually the user can just don't pass any HTML attributes with a wrapper by themselves.
@JounQin there seems to be two different discussions here:
what is possible in code
what makes sense for the API
I completely agree that is it possible, though code to support all attributes and switching HTML tags.
I also agree that flatter HTML/JSX is generally preferable.
I respectfully disagree that react-markdown should provide a magic root level tag insertion feature.
The focus of the library is to render markdown to react.
Features that are unrelated or tangential to rendering markdown, confuse the API, and should be avoided/removed.
In my mind adding random <div> attributes on top of all the markdown related attributes falls in the category of confusing/distracting.
I think it's best to leave it as is. It just doesn't seem like a pressing concern and will require users to change their code, all for something that isn't truly important.
Let's leave this as is, I think we should minimize breaking changes, especially when it's something as benign as this. It's a nice-to-have without negative consequences, no harm.
Agree with @AVGVSTVS96. It is better to keep it, at least for now. Maybe when the next necessary breaking change will be introduced - the className can be deprecated alongside
I imagine this won't be heard given that the change has been made and released, but I find this change pretty baffling and frustrating.
In previous versions, where the use was something like <Markdown text={markdownString} />, I could understand why a container div makes sense - Markdown here reads as a 'do something' component that renders markdown as JSX in-place. However, now that the syntax is <Markdown>{markdownString}</Markdown>, the component reads semantically as a container element.
In practice, when dealing with container elements (such as the <Markdown> element, which is functionally a <div> as far as layout is concerned), I almost always want to be able to make small layout changes such as padding or margins.
Now I have to add a semantically meaningless wrapper <div> element literally every time I want to use the <Markdown> component - reducing readability by adding an unnecessary extra layer of indentation and is generally just kind of inelegant-looking. Not exactly a big deal, but this entire issue was always termed in 'not a big deal' language - making it even stranger to me that it was decided to introduce this as a breaking change!
I do understand the rationale of not wanting to add every possible <div> property to the component. If someone wants to use a more obscure / specialised <div> property, then sure, requiring a wrapping <div> element makes sense. But there is very rarely going to be a time when I add a <div> element without wanting to add a custom class to it.
Ultimately, this feels to me like a pernickety change that harms real-world everyday usability for the sake of conceptual purity and it makes me sad :(
Reacted by Artem Shibakov, Alan 🍉, kartojal, Hin, Joshua Melville, Brian Smith, Irwin Arruda, YutaMoriJP and Rob
Activity
wooorm commentedon Oct 13, 2023
a) is it really worth the churn to remove a nice to have feature that isn’t super useful but well, folks might want, and also people will already have, do we really need to break peoples code
b) we always generate a block. Generating a div around blocks is fine, doesn’t cause a shift.
Sure it’s quite useless. But it isn’t bad?
One more alternative: accept all
IntrinsicAttributes['div']too.wooorm commentedon Oct 27, 2023
@remcohaszing What do you think?
remcohaszing commentedon Oct 27, 2023
I would flip the question: If we didn’t support the
classNameprop yet, would it be worth adding it, if it requires doing something unexpected (adding a wrapper element)?This behaviour is documented, but typically a
classNameprop forwards it to the top-level component, not insert one additionally.The alternative of having the user wrap
<Markdown />inside a<div />manually is much more flexible. They can add any props they want to the<div />, or even use an entirely different element.I don’t think we should remove of right away, but I think it would be nice to remove in a next major version.
wooorm commentedon Oct 27, 2023
I’m not really opposed. But I feel like the churn/discussions/etc just doesn’t matter much. There’s a lot to maintain. Feel free to PR a comment:
// To do: deprecate next major.ChristianMurphy commentedon Nov 13, 2023
I'm of a similar mind to @remcohaszing, I see a mapping of
classNameor other<div>related props as muddling the top level API.Users adding their own wrapper is more flexible and clear.
I'd lean against adding even more
<div>props before a release removing support.We want to minimize the amount of attributes users will need to change, not add more.
Would we also want to add a
devlopdeprecation notice? (https://github.com/wooorm/devlop)JounQin commentedon Nov 13, 2023
Personally I prefer fewer nested depth, so I would like to add all props instead of removing the support.
Deprecate the className prop
remcohaszing commentedon Nov 15, 2023
The problem with adding more props is, how far do you want to go?
<div>supports tens (hundreds? Infinity includingdata-*?) of props. Why<div>, and not<main>, or a custom component? Should there be anasprop?All of these choices complicate the API. Also there was simply no other way before the introduction of fragments / returning arrays. Removing the prop and promoting composition simplifies it.
JounQin commentedon Nov 16, 2023
All props can be supported via simple
{...props}, and for the tag name,divvsmaindoesn't change anything, it's just a choice. Or even it can be supported to be changed while I don't think it makes any sense.Or even the user can useReact.cloneElementeasily if they really want to hack.Actually the user can just don't pass any HTML attributes with a wrapper by themselves.
ChristianMurphy commentedon Nov 16, 2023
@JounQin there seems to be two different discussions here:
I completely agree that is it possible, though code to support all attributes and switching HTML tags.
I also agree that flatter HTML/JSX is generally preferable.
I respectfully disagree that
react-markdownshould provide a magic root level tag insertion feature.The focus of the library is to render markdown to react.
Features that are unrelated or tangential to rendering markdown, confuse the API, and should be avoided/removed.
In my mind adding random
<div>attributes on top of all the markdown related attributes falls in the category of confusing/distracting.1 remaining item
AVGVSTVS96 commentedon Jul 12, 2024
I think it's best to leave it as is. It just doesn't seem like a pressing concern and will require users to change their code, all for something that isn't truly important.
Let's leave this as is, I think we should minimize breaking changes, especially when it's something as benign as this. It's a nice-to-have without negative consequences, no harm.
ivanzusko commentedon Aug 20, 2024
Agree with @AVGVSTVS96. It is better to keep it, at least for now. Maybe when the next necessary breaking change will be introduced - the
classNamecan be deprecated alongside[-]Remove the `className` prop[/-][+]Remove support for `className` prop[/+]github-actions commentedon Feb 20, 2025
wooorm commentedon Feb 20, 2025
Released in
10.0.0!Utilise un wrapper explicite (et générique) pour le contenu markdown …
Utilise un wrapper explicite (et générique) pour le contenu markdown …
Utilise un wrapper explicite (et générique) pour le contenu markdown …
Remove support for `className` prop
lachlansleight commentedon Jun 25, 2025
I imagine this won't be heard given that the change has been made and released, but I find this change pretty baffling and frustrating.
In previous versions, where the use was something like
<Markdown text={markdownString} />, I could understand why a container div makes sense - Markdown here reads as a 'do something' component that renders markdown as JSX in-place. However, now that the syntax is<Markdown>{markdownString}</Markdown>, the component reads semantically as a container element.In practice, when dealing with container elements (such as the
<Markdown>element, which is functionally a<div>as far as layout is concerned), I almost always want to be able to make small layout changes such as padding or margins.Now I have to add a semantically meaningless wrapper
<div>element literally every time I want to use the<Markdown>component - reducing readability by adding an unnecessary extra layer of indentation and is generally just kind of inelegant-looking. Not exactly a big deal, but this entire issue was always termed in 'not a big deal' language - making it even stranger to me that it was decided to introduce this as a breaking change!I do understand the rationale of not wanting to add every possible
<div>property to the component. If someone wants to use a more obscure / specialised<div>property, then sure, requiring a wrapping<div>element makes sense. But there is very rarely going to be a time when I add a<div>element without wanting to add a custom class to it.Ultimately, this feels to me like a pernickety change that harms real-world everyday usability for the sake of conceptual purity and it makes me sad :(
Leee62 commentedon Aug 20, 2025
神人 👍
scottopherson commentedon Oct 30, 2025
@lachlansleight not the exact code but we did something like this instead: