fix: prevent duplicate child cloning of iframe content #434
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
Currently, iframe content is duplicated during the recursive
cloneNode
process. See this repo for a minimal reproduction of the issue: https://github.com/joshualoehr/html-to-image-iframe-bugI'm new to this library so it's not clear to me if there's a downside to the fix I'm proposing, or a better way to approach a solution. But all of the existing tests pass and the new test I've added covers the scenario in my repro repo.
Motivation and Context
When the iframe node is originally passed into
cloneNode
, it is forwarded tocloneSingleNode
. IncloneSingleNode
, the iframe's document body is extracted and recursively passed back intocloneNode
as another root node. That lattercloneNode
call takes care of cloning all of the iframe content just fine.However, since the original call to
cloneNode
with the iframe node is still promise-chained, it will then pass throughcloneChildren
,decorate
, andensureSVGSymbols
again, after its document body node has already done so. That causes the iframe's body and other nested contents to be cloned again, redundantly. The result is two copies of the iframe contents in the SVG.The changes in this PR stop
cloneChildren
anddecorate
from doing anything if operating on the iframe node itself, rather than its nested document body.ensureSVGSymbols
seems to be irrelevant for iframes, so I've left it alone.Types of changes
Self Check before Merge