Add HTML element constructor globals to the polyfill - #626
Open
airhorns wants to merge 2 commits into
Open
Conversation
Assisted-By: devx/ca2f43ab-bbf9-4273-b1bc-0b06f8c90a57
airhorns
force-pushed
the
polyfill-html-element-constructors
branch
from
July 28, 2026 14:21
83221d8 to
6f26eca
Compare
Assisted-By: devx/ca2f43ab-bbf9-4273-b1bc-0b06f8c90a57
JoviDeCroock
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Remote code is commonly type-checked against
lib.dom, but standard globals such asHTMLInputElementandHTMLFormElementare absent from the worker-side polyfill. An ordinary guard such aselement instanceof HTMLInputElementtherefore throws aReferenceErrorat runtime.This installs the complete HTML
*Elementconstructor set declared bylib.dom. The constructors provide tag- and namespace-awareinstanceofchecks, including grouped interfaces such asHTMLMediaElement,HTMLHeadingElement, andHTMLTableCellElement. The existingHTMLTemplateElementimplementation and registered custom-element constructors remain unchanged.Preserving the flat element model
Remote DOM deliberately represents ordinary HTML tags with one shared
Elementimplementation: 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 hasElement.prototypeandinput.constructor === Element, whileinput instanceof HTMLInputElementis true andinput instanceof HTMLFormElementis false.HTMLElementrecognizes 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 constructorwhen 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
instanceofbehavior without claiming full browser prototype-hierarchy conformance.Validation
pnpm exec vitest run(193 tests)pnpm lintpnpm type-checkmise exec node@20.20.0 -- pnpm --filter @remote-dom/polyfill build