Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`Document.parseHTMLUnsafe` drops HTML comments in Chrome 155, so swapped content loses them

Open Beginner friendly
#4,147 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

@Aashu-1911 is already working on this.

Since Oct 18, 2026.

  • #4148 by @Aashu-1911 — open
  • #4150 by @Aashu-1911 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
html, javascript
Domain
frontend

Research direction

Start by reading the HTML parsing selection introduced in #3185 and trace how htmx chooses between Document.parseHTMLUnsafe and DOMParser. Add coverage for HTML comments in swapped content, including the reported Chrome behavior, and verify the proposed configuration option selects DOMParser. Done means users can opt into parsing that preserves comments and the regression is covered by tests.

Written by the indexing model from the issue text.

Description

In Chrome 155, Document.parseHTMLUnsafe drops every HTML comment. DOMParser keeps them, and Chromium 148 kept them too. htmx 2 and htmx 4 both prefer parseHTMLUnsafe when the browser has it (since #3185), so any comment in swapped content is lost.

Input Chrome 155 parseHTMLUnsafe Chrome 155 DOMParser Chromium 148 parseHTMLUnsafe
<p>a<!-- x -->b</p> <p>ab</p> <p>a<!-- x -->b</p> <p>a<!-- x -->b</p>
<p>a<!---->b</p> <p>ab</p> <p>a<!---->b</p> <p>a<!---->b</p>

This breaks libraries that hydrate server-rendered HTML using comment markers. For example, Leptos islands swapped in by htmx 2 fail to hydrate (htmx 4 calls the same function, not tested in Chrome 155). The workaround today is delete Document.parseHTMLUnsafe before htmx loads (https://github.com/leptos-rs/leptos/pull/4910).

It's a Chrome bug, reported a month ago: https://issues.chromium.org/issues/562116090 (point 3). Passing {} as the second argument, Document.parseHTMLUnsafe(html, {}), keeps the comments, and is correct per spec. Would you take a PR for that one-line change?

Drafted with Claude, reviewed by me.

Dominant language
JavaScript
Stars
49.6k
Forks
1.7k
Avg merge
14d 7h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bigskysoftware/htmx

All issues in bigskysoftware/htmx

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.