Skip to content

Commit

Permalink
fix: issue with font flooding
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthemanuel committed Sep 20, 2023
1 parent 2247ffd commit 375af46
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
25 changes: 24 additions & 1 deletion packages/driver/cypress/e2e/dom/visibility.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('src/cypress/dom/visibility', () => {
expect(fn()).to.be.true
})

it('returns false window and body > window height', () => {
it('returns false if window and body < window height', () => {
cy.$$('body').html('<div>foo</div>')

const win = cy.state('window')
Expand All @@ -65,6 +65,29 @@ describe('src/cypress/dom/visibility', () => {
expect(fn()).to.be.false
})

it('returns true if document element and body > window height', function () {
this.add('<div style="height: 1000px; width: 10px;" />')
const documentElement = Cypress.dom.wrap(cy.state('document').documentElement)

const fn = () => {
return dom.isScrollable(documentElement)
}

expect(fn()).to.be.true
})

it('returns false if document element and body < window height', () => {
cy.$$('body').html('<div>foo</div>')

const documentElement = Cypress.dom.wrap(cy.state('document').documentElement)

const fn = () => {
return dom.isScrollable(documentElement)
}

expect(fn()).to.be.false
})

it('returns false el is not scrollable', function () {
const noScroll = this.add(`\
<div style="height: 100px; overflow: auto;">
Expand Down
40 changes: 29 additions & 11 deletions packages/driver/src/cy/actionability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,24 +460,43 @@ const verify = function (cy, $el, config, options, callbacks: VerifyCallbacks) {
// make scrolling occur instantly. we do this by adding a style tag
// and then removing it after we finish scrolling
// https://github.com/cypress-io/cypress/issues/3200
const addScrollBehaviorFix = () => {
let style
const addScrollBehaviorFix = (element: JQuery<HTMLElement>) => {
const affectedParents: Map<HTMLElement, string> = new Map()

try {
const doc = $el.get(0).ownerDocument
let parent: JQuery<HTMLElement> | null = element

style = doc.createElement('style')
style.innerHTML = '* { scroll-behavior: inherit !important; }'
// there's guaranteed to be a <script> tag, so that's the safest thing
// to query for and add the style tag after
doc.querySelector('script').after(style)
do {
if ($dom.isScrollable(parent)) {
const parentElement = parent[0]
const styles = getComputedStyle(parentElement)

if (styles.scrollBehavior === 'smooth') {
affectedParents.set(parentElement, parentElement.style.scrollBehavior)
parentElement.style.scrollBehavior = 'auto'
}
}

parent = $dom.getFirstScrollableParent(parent)
} while (parent)
} catch (err) {
// the above shouldn't error, but out of an abundance of caution, we
// ignore any errors since this fix isn't worth failing the test over
}

return () => {
if (style) style.remove()
for (const [parent, value] of affectedParents) {
if (value === '') {
if (parent.style.length === 1) {
parent.removeAttribute('style')
} else {
parent.style.removeProperty('scroll-behavior')
}
} else {
parent.style.scrollBehavior = value
}
}
affectedParents.clear()
}
}

Expand All @@ -500,8 +519,7 @@ const verify = function (cy, $el, config, options, callbacks: VerifyCallbacks) {
if (options.scrollBehavior !== false) {
// scroll the element into view
const scrollBehavior = scrollBehaviorOptionsMap[options.scrollBehavior]

const removeScrollBehaviorFix = addScrollBehaviorFix()
const removeScrollBehaviorFix = addScrollBehaviorFix($el)

debug('scrollIntoView:', $el[0])
$el.get(0).scrollIntoView({ block: scrollBehavior })
Expand Down
6 changes: 6 additions & 0 deletions packages/driver/src/dom/elements/complexElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ export const isScrollable = ($el) => {
return false
}

const documentElement = $document.getDocumentFromElement(el).documentElement

if (el === documentElement) {
return checkDocumentElement($window.getWindowByElement(el), el)
}

// if we're any other element, we do some css calculations
// to see that the overflow is correct and the scroll
// area is larger than the actual height or width
Expand Down

0 comments on commit 375af46

Please sign in to comment.