Skip to content

Add the innerHTML setter over @bomb.sh/html - #159

Open
natemoo-re wants to merge 1 commit into
mainfrom
natemoo-re/ui-inner-html-setter
Open

natemoo-re wants to merge 1 commit into
mainfrom
natemoo-re/ui-inner-html-setter

Conversation

@natemoo-re

Copy link
Copy Markdown
Member

What does this PR do?

Adds the Element#innerHTML setter, parsing with @bomb.sh/html's parseFragment from @bomb.sh/html/sink through a TreeSink that builds @clack/ui nodes. Every framework profile in frameworks.ts lists Element#innerHTML, and Solid and Svelte also use it to clone templates.

  • Atomic: the markup parses into a detached fragment, and only then replaces the children, so a failed parse leaves them in place.
  • Context: the fragment context comes from the element: localName, namespace, inForm, and htmlIntegrationPoint for MathML annotation-xml. @bomb.sh/html's fast path turns on by itself for HTML contexts that parse with plain "in body" rules.
  • Parser names: elements are created through a non-validating hook (the same static {} pattern as exposeAttributes), and attributes are added as Attr nodes. This way, names the parser produces, such as <foo:bar a:b>, aren't split or rejected by createElementNS/setAttributeNS validation.
  • Not supported yet (each throws NotSupportedError):
    • template contents, which is consistent with the serializer: setting innerHTML on a template, or markup containing one
    • XML documents
    • contexts outside the HTML, SVG and MathML namespaces
  • quirksMode isn't passed, because @clack/ui doesn't track a document mode.
  • The getter still serializes through parse5. @bomb.sh/html 0.1.0 has no serializer.

WPT now also selects the setter cases this unlocks:

  • domparsing/innerhtml-04, -07, -08
  • html/syntax/parsing: named-character-references (a file of about 2,000 subtests), cdata-in-integration-point-fragment, adoption_agency_check_the_end_tag_name, and the zero.html cases that don't read title
  • the innerHTML cases in Document-getElementById
  • the focus tests that needed the setter for setup: active-element, focusing-focused-noop

I checked each newly selected case by running it with the setter disabled: every one fails without the setter and passes with it.

Notes for review:

  • pnpm-workspace.yaml gets the same minimumReleaseAgeExclude entry for @bomb.sh/html@0.1.0 as the in-progress WPT harness migration from parse5, so whichever lands second has a one-line conflict.
  • Sink inserts still go through insertBefore and notify on each one, because the render replay depends on those dirty marks. Batching notifications for a detached fragment would be a separate perf change.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • All tests pass (pnpm test)
  • Files are formatted (pnpm format)
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​bomb.sh/​html@​0.1.0751007693100

View full report

@pkg-pr-new

pkg-pr-new Bot commented Dec 6, 2026

Copy link
Copy Markdown

commit: b4b7be9

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

Successfully merging this pull request may close these issues.

1 participant