Skip to content

Commit 1f580df

Browse files
committed
fix issue where closed shawdow doms were causing application to crash [run ci]
1 parent bbeca6b commit 1f580df

File tree

4 files changed

+367
-29
lines changed

4 files changed

+367
-29
lines changed

packages/driver/src/cy/overrides.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,25 @@ export const create = (state: StateFunc, config: ICypress['config'], focused: IF
2828

2929
// since scrolls on elements cannot see outside the shadowDOM, we want to attach
3030
// a scroll event to the shadowRoot and propagate a synthetic event to protocol
31-
this.shadowRoot.addEventListener('scroll', (event) => {
32-
const isADocument =
33-
event.target instanceof Document
34-
35-
// if this is a scroll on an element, we want to propagate it.
36-
// otherwise, document scrolls will propagate to protocol
37-
if (!isADocument) {
38-
const syntheticScrollEvent = new CustomEvent('cypress:protocol:shadow-dom:element:scroll', {
39-
bubbles: true,
40-
composed: true,
41-
detail: event,
42-
})
43-
44-
this.dispatchEvent(syntheticScrollEvent)
45-
}
46-
}, true)
31+
if (this.shadowRoot) {
32+
// shadowRoot only exists on 'open' mode shadowRoots
33+
this.shadowRoot.addEventListener('scroll', (event) => {
34+
const isADocument =
35+
event.target instanceof Document
36+
37+
// if this is a scroll on an element, we want to propagate it.
38+
// otherwise, document scrolls will propagate to protocol
39+
if (!isADocument) {
40+
const syntheticScrollEvent = new CustomEvent('cypress:protocol:shadow-dom:element:scroll', {
41+
bubbles: true,
42+
composed: true,
43+
detail: event,
44+
})
45+
46+
this.dispatchEvent(syntheticScrollEvent)
47+
}
48+
}, true)
49+
}
4750

4851
return returnVal
4952
}

0 commit comments

Comments
 (0)