Skip to content

Add HTML element constructor globals to the polyfill - #626

Open
airhorns wants to merge 2 commits into
Shopify:mainfrom
airhorns:polyfill-html-element-constructors
Open

Add HTML element constructor globals to the polyfill#626
airhorns wants to merge 2 commits into
Shopify:mainfrom
airhorns:polyfill-html-element-constructors

Conversation

@airhorns

@airhorns airhorns commented Jul 28, 2026

Copy link
Copy Markdown

What changed

Remote code is commonly type-checked against lib.dom, but standard globals such as HTMLInputElement and HTMLFormElement are absent from the worker-side polyfill. An ordinary guard such as element instanceof HTMLInputElement therefore throws a ReferenceError at runtime.

This installs the complete HTML *Element constructor set declared by lib.dom. The constructors provide tag- and namespace-aware instanceof checks, including grouped interfaces such as HTMLMediaElement, HTMLHeadingElement, and HTMLTableCellElement. The existing HTMLTemplateElement implementation and registered custom-element constructors remain unchanged.

Preserving the flat element model

Remote DOM deliberately represents ordinary HTML tags with one shared Element implementation: it is a minimal, hookable mutation tree for a worker, while tag-specific rendering and behavior live on the host. Creating a browser-style subclass for every HTML tag would add prototype identity without implementing the corresponding form, media, or layout behavior, and would move shared remote-element APIs onto an artificial hierarchy.

This PR therefore does not change Document.createElement() or the prototype of ordinary elements. For example, an input still has Element.prototype and input.constructor === Element, while input instanceof HTMLInputElement is true and input instanceof HTMLFormElement is false. HTMLElement recognizes flat XHTML elements through the same mechanism, while subclasses used for registered custom elements continue to use their real prototype chains.

Tag-specific facade constructors throw TypeError: Illegal constructor when invoked directly, matching the browser behavior of these platform constructors.

Relationship to open work

This follows the flat-model decision documented in #619. #620 lists concrete HTML constructors as deferred WPT coverage; this PR addresses global availability and useful instanceof behavior without claiming full browser prototype-hierarchy conformance.

Validation

  • pnpm exec vitest run (193 tests)
  • pnpm lint
  • pnpm type-check
  • mise exec node@20.20.0 -- pnpm --filter @remote-dom/polyfill build

Assisted-By: devx/ca2f43ab-bbf9-4273-b1bc-0b06f8c90a57
@airhorns
airhorns force-pushed the polyfill-html-element-constructors branch from 83221d8 to 6f26eca Compare July 28, 2026 14:21
Assisted-By: devx/ca2f43ab-bbf9-4273-b1bc-0b06f8c90a57
@airhorns airhorns changed the title Add concrete HTML element constructors to the polyfill Add HTML element constructor globals to the polyfill Jul 28, 2026
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.

2 participants