-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
packages/dom/src/wc-clone.js
Outdated
}; | ||
|
||
const customOuterHTML = docElement => { | ||
return `<html class="hydrated">${docElement.getInnerHTML()}</html>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general approach would be to copy the attributes on the root element over instead of hard coding class="hydrated" (which a Stencil-specific thing)
packages/dom/src/wc-clone.js
Outdated
clonedDocumentElementFragment.head = document.createDocumentFragment(); | ||
clonedDocumentElementFragment.documentElement = clonedDocumentElementFragment.firstChild; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is pretty hacky. We should rewrite the logic here to avoid adding properties onto a fragment which don't exist.
const getOuterHTML = docElement => { | ||
let innerHTML = docElement.getInnerHTML(); | ||
docElement.textContent = ''; | ||
return docElement.outerHTML.replace('</html>', `${innerHTML}</html>`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
* This enables us to capture shadow DOM in snapshots. It takes advantage of `attachShadow`'s mode option set to open | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow#parameters | ||
*/ | ||
const deepClone = host => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do we know this (not-trivial) walker works ?
do we need any tests ? or is this code copy-pasted from somewhere ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's copied from https://stackoverflow.com/a/55540552 and modified a bit. I don't think this fork is really set up to run tests.
I'd like to see the code tidied up and tested but yeah...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, but the actual clone function is a bit scary ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, because we have tried this and it works (fixes our tests) 😎
Currently, Percy does not provide support for capturing shadow dom as outlined in this issue: percy#280
@mmun previously did some exploration and created a working modification to Percy's cloning behavior that enables capturing shadow dom in Chrome. This PR contains the modification necessary to allow shadow dom to be properly cloned.