Skip to content

Fix exported DOM Element instanceof checks - #2243

Merged
remarkablemark merged 1 commit into
remarkablemark:masterfrom
sjh9714:fix-element-instanceof-regression
May 16, 2026
Merged

Fix exported DOM Element instanceof checks#2243
remarkablemark merged 1 commit into
remarkablemark:masterfrom
sjh9714:fix-element-instanceof-regression

Conversation

@sjh9714

@sjh9714sjh9714 commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes instanceof checks for DOM elements passed to the replace callback.

What changed

  • Added a regression test for exported Element instances in replace.
  • Normalized parser-created DOM element prototypes to the Element class exported by this package.

Why

html-dom-parser can create DOM element instances whose class reference differs from the Element class exported by html-react-parser. That breaks documented checks like domNode instanceof Element.

Testing

  • npm run prepublishOnly
  • npm run test:esm
  • npm run test:browser

Fixes#2198

@codecov

codecovBot commented May 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f7e66d8) to head (fe88b54).

Additional details and impacted files
@@ Coverage Diff @@## master #2243 +/- ##
=========================================
Coverage 100.00% 100.00% =========================================
Files 4 4 Lines 127 136 +9 Branches 48 52 +4 =========================================
+ Hits 127 136 +9 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment threadsrc/index.ts Outdated
Comment threadsrc/index.ts Outdated
Comment threadsrc/index.ts Outdated
remarkablemark

This comment was marked as outdated.

@remarkablemarkremarkablemark added the bug Something isn't working label May 16, 2026
@sjh9714
sjh9714force-pushed the fix-element-instanceof-regression branch from 55928ae to b9e8a92CompareMay 16, 2026 02:03
@sjh9714

Copy link
Copy Markdown
ContributorAuthor

Thanks, I took another pass at this. I moved the normalization into domToReact, which also addresses your earlier question about keeping this out of index.ts, and the generated root declarations are back to the direct export { Comment, Element, ProcessingInstruction, Text } from 'domhandler' form.

I also added regression coverage for DOM node references exposed in replace (children and next) so the callback does not only work for the current node.

Local checks run:

  • npm run prepublishOnly
  • npm run test:esm
  • npm run test:browser
  • git diff --check

The new GitHub Actions runs for commit b9e8a92 are currently showing action_required with no jobs, so I cannot see the updated type-lint result until the workflows are approved/run.

Comment threadsrc/dom-to-react.ts

@remarkablemarkremarkablemark left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! Let me know if you see this GitHub Action workflow run.

@sjh9714
sjh9714force-pushed the fix-element-instanceof-regression branch from b9e8a92 to fe88b54CompareMay 16, 2026 02:22
@sjh9714sjh9714 changed the title Fix exported DOM class instanceof checksFix exported DOM Element instanceof checksMay 16, 2026
@sjh9714

Copy link
Copy Markdown
ContributorAuthor

I can see the workflow run now. The b9e8a92 lint job failed at the same @arethetypeswrong/cli --pack step with Cannot read properties of undefined (reading 'filename'); build, commitlint, size, tests, and Codecov passed.\n\nI pushed fe88b54 with a narrower change: only Element nodes are normalized, and the PR title/body now match that scope. Local checks run after the update:\n\n- npm run prepublishOnly\n- npm run test:esm\n- npm run test:browser\n- git diff --check\n\nI also tried npx @arethetypeswrong/cli --pack -f json locally, but it exits with the same internal filename error before producing JSON. The new GitHub Actions runs for fe88b54 are currently action_required, so I cannot see the updated job logs until they are approved/run.

@remarkablemark

remarkablemark commented May 16, 2026

Copy link
Copy Markdown
Owner

@jinhyuk9714 I think the error might be due to something else. I'll go ahead and merge this PR

Update: the error is unrelated to your changes and is coming from arethetypeswrong/arethetypeswrong.github.io#258

@remarkablemark
remarkablemark merged commit cfa0e0e into remarkablemark:masterMay 16, 2026
11 of 12 checks passed
@remarkablemark

Copy link
Copy Markdown
Owner

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

Labels

bugSomething isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

instanceof Element broken in v6.0.1 — exported Element class differs from internal parser Element

2 participants

@sjh9714@remarkablemark