fix: prevent iframe content from being cloned twice#576
fix: prevent iframe content from being cloned twice#576Sunyi-000 wants to merge 2 commits intobubkoo:masterfrom
Conversation
| <iframe | ||
| id="test-iframe" | ||
| style="width:100%;height:100%;border:none;" | ||
| srcdoc="<html><body><p class='iframe-para' data-testid='iframe-para'>IFRAME_CONTENT</p></body></html>" |
There was a problem hiding this comment.
WCAG 2.4.2: Document is missing a <title> element.
Documents must have a <title> element to provide users with an overview of content.
Details
Screen reader users rely on page titles to identify and navigate between tabs/windows. Add a descriptive <title> element in <head> that summarizes the page purpose. Keep titles unique across the site, placing specific content before the site name (e.g., 'Contact Us - Acme Corp').
Best Practice: Page has no mechanism to bypass repeated content. Add a <main> landmark or skip link.
Page must have a mechanism to bypass repeated blocks of content.
Details
Missing: no landmarks (<main>, <nav>, <header>, <footer>), no skip link, no headings
Keyboard users must be able to skip repetitive content like navigation. Provide a skip link at the top of the page that links to the main content (e.g., <a href="#main">Skip to main content</a>), or use a <main> landmark. Screen readers can jump directly to landmarks, so a properly marked-up <main> element satisfies this requirement.
Best Practice: Page does not contain a level-one heading.
Page should contain a level-one heading.
Details
A level-one heading (<h1> or role='heading' with aria-level='1') helps users understand the page topic and provides a landmark for screen reader navigation. Each page should have exactly one h1 that describes the main content, typically matching or similar to the page title.
Best Practice: Page has no main landmark.
Page should have exactly one main landmark.
Details
The main landmark contains the primary content of the page. Screen readers allow users to jump directly to main content. Use a single <main> element (or role='main') to wrap the central content, excluding headers, footers, and navigation.
WCAG 3.1.1: <html> element missing lang attribute.
The <html> element must have a lang attribute.
Details
Screen readers use the lang attribute to determine which language rules and pronunciation to use. Without it, content may be mispronounced. Set lang to the primary language of the page (e.g., lang='en' for English, lang='es' for Spanish).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #576 +/- ##
=======================================
Coverage 66.50% 66.50%
=======================================
Files 10 10
Lines 612 612
Branches 150 150
=======================================
Hits 407 407
Misses 144 144
Partials 61 61 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cloneIFrameElement (called via cloneSingleNode) already recursively clones the entire iframe contentDocument.body. The subsequent call to cloneChildren was then also iterating contentDocument.body.childNodes and appending them again, duplicating every child element. Fix: return early from cloneChildren when the native node is an iframe, since its subtree is fully handled by cloneIFrameElement. Closes bubkoo#543 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9d648f1 to
c264a4a
Compare
|
Note on Codecov patch coverage: The |
Add title attribute to <iframe> element (WCAG best practice) and include a proper HTML document structure inside srcdoc (DOCTYPE, lang, <title>) to satisfy WCAG 2.4.2 (page-titled) and 3.1.1 (language of page). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| id="test-iframe" | ||
| title="Test iframe content" | ||
| style="width:100%;height:100%;border:none;" | ||
| srcdoc="<!DOCTYPE html><html lang='en'><head><title>iframe test</title></head><body><p class='iframe-para' data-testid='iframe-para'>IFRAME_CONTENT</p></body></html>" |
There was a problem hiding this comment.
WCAG 2.4.2: Document is missing a <title> element.
Documents must have a <title> element to provide users with an overview of content.
Details
Screen reader users rely on page titles to identify and navigate between tabs/windows. Add a descriptive <title> element in <head> that summarizes the page purpose. Keep titles unique across the site, placing specific content before the site name (e.g., 'Contact Us - Acme Corp').
Best Practice: Page has no mechanism to bypass repeated content. Add a <main> landmark or skip link.
Page must have a mechanism to bypass repeated blocks of content.
Details
Missing: no landmarks (<main>, <nav>, <header>, <footer>), no skip link, no headings
Keyboard users must be able to skip repetitive content like navigation. Provide a skip link at the top of the page that links to the main content (e.g., <a href="#main">Skip to main content</a>), or use a <main> landmark. Screen readers can jump directly to landmarks, so a properly marked-up <main> element satisfies this requirement.
Best Practice: Page does not contain a level-one heading.
Page should contain a level-one heading.
Details
A level-one heading (<h1> or role='heading' with aria-level='1') helps users understand the page topic and provides a landmark for screen reader navigation. Each page should have exactly one h1 that describes the main content, typically matching or similar to the page title.
Best Practice: Page has no main landmark.
Page should have exactly one main landmark.
Details
The main landmark contains the primary content of the page. Screen readers allow users to jump directly to main content. Use a single <main> element (or role='main') to wrap the central content, excluding headers, footers, and navigation.
WCAG 3.1.1: <html> element missing lang attribute.
The <html> element must have a lang attribute.
Details
Screen readers use the lang attribute to determine which language rules and pronunciation to use. Without it, content may be mispronounced. Set lang to the primary language of the page (e.g., lang='en' for English, lang='es' for Spanish).
Problem
Closes #543
When cloning a node that contains an
<iframe>, the iframe content was duplicated in the output.Root cause
cloneNoderuns:cloneSingleNode(iframe)→ callscloneIFrameElement→ recursively clones the fullcontentDocument.body(including all descendants)cloneChildren(iframe, clonedBody)→ findsisInstanceOfElement(nativeNode, HTMLIFrameElement)is true → appendscontentDocument.body.childNodesagainEvery child of the iframe body therefore appears twice in the cloned output.
Fix
Return early from
cloneChildrenwhen the native node is anHTMLIFrameElement.Test
Added regression test in
test/spec/special.spec.ts:<iframe srcdoc="...">containing a.iframe-paraelementcloneNodedirectly.iframe-paraappears exactly once in the cloned tree (would be 2 without the fix)