Skip to content

domNode instanceof Element is always false #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tsdexter opened this issue Jun 30, 2022 · 1 comment
Closed

domNode instanceof Element is always false #616

tsdexter opened this issue Jun 30, 2022 · 1 comment

Comments

@tsdexter
Copy link

tsdexter commented Jun 30, 2022

Expected Behavior

domNode instanceof Element should be true

Actual Behavior

domNode instanceof Element is always false

Steps to Reproduce

const WordpressContent = ({ html }: IWordpressContentProps): JSX.Element => {
  const options: HTMLReactParserOptions = {
    replace: (domNode: DOMNode) => {
      console.log({ domNode, element: domNode instanceof Element })
      if (
        domNode instanceof Element &&
        domNode.attribs &&
        domNode.attribs.class === "wp-block-page-header"
      ) {
        return <div className="border-8 border-red-500">{domToReact(domNode.children, options)}</div>
      }
    }
  }
  return <div className="border-8 border-purple-500">{parse(html, options)}</div>
}

Results in logs like below and nothing is replaced

domNode: Element {type: 'tag', parent: null, prev: null, next: null, startIndex: null, …}
element: false

Environment

  • Version: 2.0.0
  • Platform: OSX 12.4
  • Browser: Chrome
@tsdexter
Copy link
Author

using a typeguard worked for me #221 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant