Skip to content

Remove support for className prop #781

Closed

Description

@remcohaszing

Initial checklist

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:

import Markdown from 'react-markdown'

export function Component({ children }) {
  return (
    <Markdown className="some-class">
      {children}
    </Markdown>
  )
}
import Markdown from 'react-markdown'

export function Component({ children }) {
  return (
    <div className="some-class">
      <Markdown>
        {children}
      </Markdown>
    </div>
  )
}

Solution

Deprecate the className prop, and remove it in then next semver major release.

Alternatives

  • Do nothing.
  • Don’t deprecate it.
  • Make a semver major release just for this.

Activity

  1. added
    🗄 area/interface
    🧑 semver/major
    💬 type/discussion
    🤞 phase/open
    on Oct 13, 2023
  2. wooorm commented on Oct 13, 2023

    @wooorm
    Member

    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.

  3. wooorm commented on Oct 27, 2023

    @wooorm
    Member

    @remcohaszing What do you think?

  4. remcohaszing commented on Oct 27, 2023

    @remcohaszing
    MemberAuthor

    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.

  5. wooorm commented on Oct 27, 2023

    @wooorm
    Member

    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.

  6. ChristianMurphy commented on Nov 13, 2023

    @ChristianMurphy
    Member

    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.

    Feel free to PR a comment

    Would we also want to add a devlop deprecation notice? (https://github.com/wooorm/devlop)

  7. JounQin commented on Nov 13, 2023

    @JounQin
    Member

    Personally I prefer fewer nested depth, so I would like to add all props instead of removing the support.

  8. added a commit that references this issue on Nov 15, 2023
    ea2fa56
  9. remcohaszing commented on Nov 15, 2023

    @remcohaszing
    MemberAuthor

    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.

  10. JounQin commented on Nov 16, 2023

    @JounQin
    Member

    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.

  11. ChristianMurphy commented on Nov 16, 2023

    @ChristianMurphy
    Member

    @JounQin there seems to be two different discussions here:

    1. what is possible in code
    2. 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.

  12. 1 remaining item

  13. AVGVSTVS96 commented on Jul 12, 2024

    @AVGVSTVS96

    Yeah, think that’s easiest. Removing it.

    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.

  14. ivanzusko commented on Aug 20, 2024

    @ivanzusko

    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

  15. changed the title [-]Remove the `className` prop[/-] [+]Remove support for `className` prop[/+] on Feb 13, 2025
  16. github-actions commented on Feb 20, 2025

    @github-actions
  17. removed
    🤞 phase/open
    on Feb 20, 2025
  18. wooorm commented on Feb 20, 2025

    @wooorm
    Member

    Released in 10.0.0!

  19. added a commit that references this issue on Feb 20, 2025
    aaaa40b
  20. lachlansleight commented on Jun 25, 2025

    @lachlansleight

    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 :(

  21. Leee62 commented on Aug 20, 2025

    @Leee62

    神人 👍

  22. scottopherson commented on Oct 30, 2025

    @scottopherson

    @lachlansleight not the exact code but we did something like this instead:

    import ReactMarkdown from "react-markdown";
    
    export function Markdown({ children, ContainerProps = {}, MarkdownProps = {} }) {
      return (
        <div {...ContainerProps}>
          <ReactMarkdown {...MarkdownProps}>
            {children}
          </ReactMarkdown>
        </div>
      );
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    💪 phase/solved💬 type/discussion🗄 area/interface🧑 semver/major

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions