Change cloneNode references to importNode #41441
Open
+9
−9
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.
Description
Updated examples to use
document.importNode()
exclusively, and references to refer to bothimportNode
andNode.cloneNode
.Motivation
document.importNode
andNode.cloneNode
are largely similar, but have one important difference; the timing of when the node is adopted. When usingNode.cloneNode()
, the content isn't adopted until it's either explicitly adopted or when it's appended to the document, so at a later point after callingcloneNode()
. This falls into an edge-case annoyance where calling upgrade on nodes that aren't yet adopted causes them to not actually get upgraded. This real example from the Web Components discord demonstrates the edge-case:If you change from
content.cloneNode()
todocument.importNode()
then the constructor will run and the content is upgraded correctly.So we would like to update the examples to show
document.importNode()
being used by default, and also update references/links to show it as an option next to cloneNode.Additional details
Web components discord discussion https://discord.com/channels/767813449048260658/767813449048260661/1421037073829199994
Related issues and pull requests