Skip to content

Parsing html tag without body tag failed #818

Open

Description

@harryzcy

Expected Behavior

parse('<html><p>Hello, World!</p></html>') should return a html tag, with a p child tag

Actual Behavior

It returns empty react element. console.log gives the following:

{
  ...
  props: {children: null}
  ...
}

Steps to Reproduce

Call parse('<html><p>Hello, World!</p></html>')

Reproducible Demo

Environment

  • Version: v3.0.8
  • Platform: node v18.12.1, TypeScript 4.9.5
  • Browser: Chrome v108
  • OS: macOS

Keywords

Activity

  1. remarkablemark commented on Feb 11, 2023

    @remarkablemark
    Owner

    @harryzcy This is expected behavior since if you're trying to render an <html> tag inside of a root element in a <body>, then you'll get the error:

    Warning: validateDOMNesting(...): <html> cannot appear as a child of <div>.
    

    See reproduced demo.

    This leads me to the question: are you unable to strip out the <html> from your string before parsing?

  2. added
    wontfixThis will not be worked on
    and removed
    bugSomething isn't working
    on Feb 11, 2023
  3. harryzcy commented on Feb 15, 2023

    @harryzcy
    Author

    That's not the point I'm making. The warning that <html> cannot appear as a child of <div> is for when it's actually rendered in browser. But the bug I'm pointing out here is when it's parsed by html-react-parser, before it's even rendered by the browser.

    I'm using the replace function in HTMLReactParserOptions to replace out the html tag, but it's not working for this specific case.

    For reference, parse('<html><body><p>Hello, World!</p></body></html>') does work but parse('<html><p>Hello, World!</p></html>') doesn't. See this demo

    So I still think it's a bug within the library.

  4. remarkablemark commented on Mar 4, 2023

    @remarkablemark
    Owner

    Hmm perhaps I am misunderstanding something @harryzcy, but your demo seems to be working correctly? I inspected the console output and it is rendering html > body > p and text

  5. harryzcy commented on Mar 4, 2023

    @harryzcy
    Author

    My demo is the working example that has parse('<html><body><p>Hello, World!</p></body></html>'). Your demo exactly shows when it's not working, when it's parse('<html><p>Hello, World!</p></html>') without the body tag. @remarkablemark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wontfixThis will not be worked on

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions