Skip to content

instanceof Text broken in v6 — exported Text class differs from internal parser Text #2256

Description

@d4nzS

Expected Behavior

When using the replace callback, domNode instanceof Text should return true for text nodes.

Actual Behavior

domNode instanceof Text returns false for all nodes in v6, even though domNode.constructor.name is "Text".

Activity

  1. remarkablemark commented on May 20, 2026

    @remarkablemark
    Owner

    Are you using latest version? #2243 should fix this issue.

  2. d4nzS commented on May 21, 2026

    @d4nzS
    Author

    Are you using latest version? #2243 should fix this issue.

    I am using 6.1.1 but it doesn't work as expected

  3. jramstedt commented on May 21, 2026

    @jramstedt

    I can verify that instanceof Text is still broken.

    I have used this workaround:

    function isText (node: DOMNode) {
      return node.nodeType === 3
    }
    
  4. remarkablemark commented on May 21, 2026

    @remarkablemark
    Owner

    Gotcha and just confirming, are your dependency versions consistent?

    npm ls domhandler htmlparser2

    You should be using:

    • domhandler@6.0.1
    • htmlparser2@12.0.0
  5. d4nzS commented on May 21, 2026

    @d4nzS
    Author

    Gotcha and just confirming, are your dependency versions consistent?

    npm ls domhandler htmlparser2
    You should be using:

    • domhandler@6.0.1
    • htmlparser2@12.0.0

    Sure

  6. MattIPv4 commented on May 29, 2026

    @MattIPv4

    👋 We're also running into this on html-react-parser@6.1.1, with domhandler@6.0.1 and htmlparser2@12.0.0.

  7. ashwinmridul commented on Sep 17, 2026

    @ashwinmridul
    Contributor

    I'll take this. #2243 only resets the prototype for tag/script/style nodes, so instanceof Text (and Comment) still fail. I'll extend that same setPrototypeOf path to text/comment nodes and add a regression.

  8. remarkablemark commented on Sep 17, 2026

    @remarkablemark
    Owner
  9. added a commit that references this issue on Oct 25, 2026
    bbcdb29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions