@@ -37,8 +37,8 @@ interface CustomScrollAction {
3737}
3838
3939// @TODO better shadowdom test, 11 = document fragment
40- function isElement ( el : any ) {
41- return el != null && typeof el === 'object' && el . nodeType === 1
40+ function isElement ( el : any ) : el is Element {
41+ return typeof el === 'object' && el != null && el . nodeType === 1
4242}
4343
4444function canOverflow (
@@ -257,10 +257,10 @@ export default (target: Element, options: Options): CustomScrollAction[] => {
257257
258258 // Collect all the scrolling boxes, as defined in the spec: https://drafts.csswg.org/cssom-view/#scrolling-box
259259 const frames : Element [ ] = [ ]
260- let cursor = target
260+ let cursor : Element | null = target
261261 while ( isElement ( cursor ) && checkBoundary ( cursor ) ) {
262262 // Move cursor to parent
263- cursor = cursor . parentNode as Element
263+ cursor = cursor . parentElement
264264
265265 // Stop when we reach the viewport
266266 if ( cursor === scrollingElement ) {
@@ -270,15 +270,16 @@ export default (target: Element, options: Options): CustomScrollAction[] => {
270270
271271 // Skip document.body if it's not the scrollingElement and documentElement isn't independently scrollable
272272 if (
273+ cursor != null &&
273274 cursor === document . body &&
274275 isScrollable ( cursor ) &&
275- ! isScrollable ( document . documentElement as HTMLElement )
276+ ! isScrollable ( document . documentElement )
276277 ) {
277278 continue
278279 }
279280
280281 // Now we check if the element is scrollable, this code only runs if the loop haven't already hit the viewport or a custom boundary
281- if ( isScrollable ( cursor , skipOverflowHiddenElements ) ) {
282+ if ( cursor != null && isScrollable ( cursor , skipOverflowHiddenElements ) ) {
282283 frames . push ( cursor )
283284 }
284285 }
0 commit comments