From a4bc1b1e20bd334cad478cfb5cdda947d88dba5c Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Fri, 24 Jul 2020 04:43:31 -0400 Subject: [PATCH 1/6] fix: prevent XHR requests from getting stuck in an infinite retry loop --- packages/driver/src/cy/snapshots.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/driver/src/cy/snapshots.js b/packages/driver/src/cy/snapshots.js index 316ff0514288..cbde8c21638f 100644 --- a/packages/driver/src/cy/snapshots.js +++ b/packages/driver/src/cy/snapshots.js @@ -147,7 +147,12 @@ const create = ($$, state) => { // TODO: throw error here if cy is undefined! - const $body = $$('body').clone() + // for some reason certain libraries (ex. polymer) + // get stuck here at cloneNode within $().clone() + // so we have to use importNode to prevent hanging + // and then re-wrap in jQuery + // https://github.com/cypress-io/cypress/issues/1068 + const $body = $$(document.importNode($$('body')[0], true)) // for the head and body, get an array of all CSS, // whether it's links or style tags From 88f6fb9ce7858b8ec7983c5131101ab7e25ff2de Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Fri, 24 Jul 2020 05:54:52 -0400 Subject: [PATCH 2/6] Fix ownership issues with cloning doc for snapshot --- packages/driver/src/cy/snapshots.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/driver/src/cy/snapshots.js b/packages/driver/src/cy/snapshots.js index cbde8c21638f..de1ceff06119 100644 --- a/packages/driver/src/cy/snapshots.js +++ b/packages/driver/src/cy/snapshots.js @@ -147,12 +147,12 @@ const create = ($$, state) => { // TODO: throw error here if cy is undefined! - // for some reason certain libraries (ex. polymer) - // get stuck here at cloneNode within $().clone() - // so we have to use importNode to prevent hanging - // and then re-wrap in jQuery + // certain frameworks (ex. polymer) which use the shadow DOM + // get stuck here if we try to use cloneNode + // so we have to use importNode to clone the element + // to the outer doc and then reassign ownership to the original doc // https://github.com/cypress-io/cypress/issues/1068 - const $body = $$(document.importNode($$('body')[0], true)) + const $body = $$(state('document').adoptNode(document.importNode($$('body')[0], true))) // for the head and body, get an array of all CSS, // whether it's links or style tags From 7c7ccfc2d8b3f8c9380152d7b89b6b336212cef5 Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Sun, 26 Jul 2020 19:25:31 -0400 Subject: [PATCH 3/6] Update comment explanation --- packages/driver/src/cy/snapshots.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/driver/src/cy/snapshots.js b/packages/driver/src/cy/snapshots.js index de1ceff06119..52d4004f5729 100644 --- a/packages/driver/src/cy/snapshots.js +++ b/packages/driver/src/cy/snapshots.js @@ -147,10 +147,10 @@ const create = ($$, state) => { // TODO: throw error here if cy is undefined! - // certain frameworks (ex. polymer) which use the shadow DOM - // get stuck here if we try to use cloneNode + // cloneNode can actually trigger functions attached to custom elements // so we have to use importNode to clone the element // to the outer doc and then reassign ownership to the original doc + // https://github.com/cypress-io/cypress/issues/7187 // https://github.com/cypress-io/cypress/issues/1068 const $body = $$(state('document').adoptNode(document.importNode($$('body')[0], true))) From febc80ede0cd11b2a50b397265870b5e577f7a7c Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Sun, 26 Jul 2020 21:16:57 -0400 Subject: [PATCH 4/6] Add tests --- .../driver/cypress/fixtures/shadow-dom.html | 18 ++++++++++++++ .../cypress/integration/cy/snapshot_spec.js | 24 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/driver/cypress/fixtures/shadow-dom.html b/packages/driver/cypress/fixtures/shadow-dom.html index ecb3ed20eeef..e6312c027c41 100644 --- a/packages/driver/cypress/fixtures/shadow-dom.html +++ b/packages/driver/cypress/fixtures/shadow-dom.html @@ -20,7 +20,13 @@ + + + + diff --git a/packages/driver/cypress/fixtures/shadow-dom.html b/packages/driver/cypress/fixtures/shadow-dom.html index e6312c027c41..ecb3ed20eeef 100644 --- a/packages/driver/cypress/fixtures/shadow-dom.html +++ b/packages/driver/cypress/fixtures/shadow-dom.html @@ -20,13 +20,7 @@ - -