Skip to content

Commit

Permalink
cloneNode pass ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
samarsault committed Jan 16, 2023
1 parent 2279b4b commit 5f72303
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/dom/src/clone-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ const deepClone = (host, disableShadowDom = false) => {
/**
* Deep clone a document while also preserving shadow roots and converting adoptedStylesheets to <style> tags.
*/
const cloneNodeAndShadow = (doc, disableShadowDom = false) => {
let mockDocumentFragment = deepClone(doc.documentElement, disableShadowDom);
const cloneNodeAndShadow = (ctx) => {
let mockDocumentFragment = deepClone(ctx.dom.documentElement, ctx.disableShadowDom);
// convert document fragment to document object
let cloneDocument = doc.cloneNode();
let cloneDocument = ctx.dom.cloneNode();
// dissolve document fragment in clone document
cloneDocument.appendChild(mockDocumentFragment);
return cloneDocument;
Expand Down
5 changes: 3 additions & 2 deletions packages/dom/src/serialize-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ export function serializeDOM(options) {
let ctx = {
resources: new Set(),
warnings: new Set(),
enableJavaScript
enableJavaScript,
disableShadowDom
};

ctx.dom = dom;
ctx.clone = cloneNodeAndShadow(ctx.dom, disableShadowDom);
ctx.clone = cloneNodeAndShadow(ctx);

serializeInputs(ctx);
serializeFrames(ctx);
Expand Down

0 comments on commit 5f72303

Please sign in to comment.