Skip to content

Update parseHTML to use Document.parseHTMLUnsafe where supported#3185

Merged
1cg merged 1 commit into
bigskysoftware:devfrom
lukewarlow:Document-parseHTMLUnsafe
Oct 17, 2025
Merged

Update parseHTML to use Document.parseHTMLUnsafe where supported#3185
1cg merged 1 commit into
bigskysoftware:devfrom
lukewarlow:Document-parseHTMLUnsafe

Conversation

@lukewarlow
Copy link
Copy Markdown
Contributor

Description

Updates parseHTML to use Document.parseHTMLUnsafe where supported

This allows HTMX to support declarative shadow dom

Corresponding issue: #2682

Testing

Please explain how you tested this change manually, and, if applicable, what new tests you added. If
you're making a change to just the website, you can omit this section.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@lukewarlow
Copy link
Copy Markdown
Contributor Author

Not sure how best to test this?

@lukewarlow
Copy link
Copy Markdown
Contributor Author

You can compare specs at https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring and https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsehtmlunsafe

These should be identical behaviour wise, except perhaps for the URL setting of the resultant document but I don't believe that's an issue for HTMX's use case.

@lukewarlow
Copy link
Copy Markdown
Contributor Author

cleanInnerHtmlForHistory it'll be interesting to see if this might need updating, currently it returns innerHTML which serialises in a way that won't include declarative shadow dom. It might be that we need to swap that for getHTML()

@Telroshan Telroshan added the enhancement New feature or request label Feb 13, 2025
@alexpetros
Copy link
Copy Markdown
Collaborator

I support this!

@alexpetros alexpetros added the ready for review Issues that are ready to be considered for merging label Jul 22, 2025
@1cg 1cg merged commit b9336a9 into bigskysoftware:dev Oct 17, 2025
@1cg
Copy link
Copy Markdown
Contributor

1cg commented Oct 17, 2025

@MichaelWest22 is going to put this behind a config flag to ensure no semantic changes for existing users. Thank you!

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

Labels

enhancement New feature or request ready for review Issues that are ready to be considered for merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants