Reject document cloning and importing explicitly - #684
Open
olavoasantos wants to merge 1 commit into
Open
olavoasantos wants to merge 1 commit into
olavoasantos wants to merge 1 commit into
Conversation
olavoasantos
force-pushed
the
deliberate-document-cloning
branch
from
September 3, 2026 15:29
78a2911 to
e07f423
Compare
olavoasantos
force-pushed
the
deliberate-document-cloning
branch
from
September 4, 2026 14:31
e07f423 to
8d31750
Compare
olavoasantos
marked this pull request as ready for review
September 14, 2026 18:41
marvinhagemeister
approved these changes
Sep 15, 2026
JoviDeCroock
approved these changes
Sep 15, 2026
henrytao-me
approved these changes
Sep 15, 2026
olavoasantos
force-pushed
the
deliberate-document-cloning
branch
from
September 16, 2026 13:57
8d31750 to
bf0153c
Compare
olavoasantos
force-pushed
the
deliberate-document-cloning
branch
from
September 16, 2026 14:08
bf0153c to
0e8e21c
Compare
olavoasantos
force-pushed
the
deliberate-document-cloning
branch
from
September 16, 2026 20:13
0e8e21c to
77e41b6
Compare
olavoasantos
removed this pull request from stack #700
September 16, 2026 20:14
olavoasantos
added this pull request to stack #717
September 16, 2026 20:15
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.
Problem
Document.cloneNode()andDocument.importNode(document)entered the generic cloning path, which cannot deliberately construct a document node. Instead of declaring whether this unsupported operation was available, the polyfill leaked incidental internalTypeErrors.Impact
Minor. Code that attempts to clone or import a document receives an implementation accident rather than a stable, recognizable DOM error, so it cannot reliably distinguish this unsupported operation from an unrelated programming failure.
Reproduction
Before this change, both calls failed through the generic clone implementation with incidental internal errors. They now throw a
NotSupportedErrorwith a clear operation-specific message; cloning and importing ordinary document descendants remains supported.Change
Detect document nodes before entering the generic clone path. Both
Document.importNode()andcloneNode()now reject them with a namedNotSupportedError, usingDOMExceptionwhere available and anErrorwith the same name as a fallback.Tests
Adds
packages/polyfill/source/tests/document-clone-import-contract.test.ts, covering shallow and deep document cloning/importing, the error name and messages, the no-DOMExceptionfallback, and successful cloning/importing ofdocument.documentElement.Stack
preserve-clone-namespacesValidation
Fresh GitHub CI on restacked head
8d31750passes: