From 16d643082718d2e64a4ac9b056d1e7b4a10adf76 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Tue, 14 Nov 2023 11:10:34 -0600 Subject: [PATCH] fix: performance regression due to enabling ScopeMemoryCachePerContext (#28327) --- cli/CHANGELOG.md | 1 + .../cypress/e2e/commands/actions/click.cy.js | 13 ++++++ .../driver/cypress/e2e/dom/visibility.cy.ts | 25 ++++++++++- packages/driver/src/cy/actionability.ts | 44 ++++++++++++++----- .../src/dom/elements/complexElements.ts | 7 +++ .../driver/src/dom/elements/nativeProps.ts | 5 +++ packages/server/lib/browsers/chrome.ts | 3 -- packages/server/lib/cypress.js | 9 +--- packages/server/lib/util/electron-app.js | 13 ------ system-tests/__snapshots__/protocol_spec.js | 44 +++++++++++++++++++ system-tests/test/protocol_spec.js | 2 +- 11 files changed, 130 insertions(+), 36 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 672a2ab47fbe..6268ac5f0c3b 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -5,6 +5,7 @@ _Released 11/21/2023 (PENDING)_ **Bugfixes:** +- Fixed a regression in [`13.5.0`](https://docs.cypress.io/guides/references/changelog/13.5.0) where requests cached within a given spec may take longer to load than they did previously. Addresses [#28295](https://github.com/cypress-io/cypress/issues/28295). - Fixed an issue where pages opened in a new tab were missing response headers, causing them not to load properly. Fixes [#28293](https://github.com/cypress-io/cypress/issues/28293) and [#28303](https://github.com/cypress-io/cypress/issues/28303). - We now pass a flag to Chromium browsers to disable default component extensions. This is a common flag passed during browser automation. Fixed in [#28294](https://github.com/cypress-io/cypress/pull/28294). diff --git a/packages/driver/cypress/e2e/commands/actions/click.cy.js b/packages/driver/cypress/e2e/commands/actions/click.cy.js index 97fe26a7b6a0..fe7ff9d81ffd 100644 --- a/packages/driver/cypress/e2e/commands/actions/click.cy.js +++ b/packages/driver/cypress/e2e/commands/actions/click.cy.js @@ -1678,12 +1678,25 @@ describe('src/cy/commands/actions/click', () => { it('can scroll to and click elements in html with scroll-behavior: smooth', () => { cy.get('html').invoke('css', 'scrollBehavior', 'smooth') cy.get('#table tr:first').click() + // Validate that the scrollBehavior is still smooth even after the actionability fixes we do + cy.get('html').invoke('css', 'scrollBehavior').then((scrollBehavior) => expect(scrollBehavior).to.eq('smooth')) + }) + + // https://github.com/cypress-io/cypress/issues/28150 + it('can scroll to and click elements in html with scroll-behavior: smooth and overflow-y: auto', () => { + cy.get('html').invoke('css', 'scrollBehavior', 'smooth') + cy.get('body').invoke('css', 'overflow-y', 'auto') + cy.get('#table tr:first').click() + // Validate that the scrollBehavior is still smooth even after the actionability fixes we do + cy.get('html').invoke('css', 'scrollBehavior').then((scrollBehavior) => expect(scrollBehavior).to.eq('smooth')) }) // https://github.com/cypress-io/cypress/issues/3200 it('can scroll to and click elements in ancestor element with scroll-behavior: smooth', () => { cy.get('#dom').invoke('css', 'scrollBehavior', 'smooth') cy.get('#table tr:first').click() + // Validate that the scrollBehavior is still smooth even after the actionability fixes we do + cy.get('#dom').invoke('css', 'scrollBehavior').then((scrollBehavior) => expect(scrollBehavior).to.eq('smooth')) }) }) }) diff --git a/packages/driver/cypress/e2e/dom/visibility.cy.ts b/packages/driver/cypress/e2e/dom/visibility.cy.ts index eed827b883b1..5dc7495afc30 100644 --- a/packages/driver/cypress/e2e/dom/visibility.cy.ts +++ b/packages/driver/cypress/e2e/dom/visibility.cy.ts @@ -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('
foo
') const win = cy.state('window') @@ -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('
') + 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('
foo
') + + 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(`\
diff --git a/packages/driver/src/cy/actionability.ts b/packages/driver/src/cy/actionability.ts index 8cdea1e51cbe..6e485c405622 100644 --- a/packages/driver/src/cy/actionability.ts +++ b/packages/driver/src/cy/actionability.ts @@ -8,6 +8,7 @@ import $utils from './../cypress/utils' import type { ElWindowPostion, ElViewportPostion, ElementPositioning } from '../dom/coordinates' import $elements from '../dom/elements' import $errUtils from '../cypress/error_utils' +import { callNativeMethod, getNativeProp } from '../dom/elements/nativeProps' const debug = debugFn('cypress:driver:actionability') const delay = 50 @@ -460,24 +461,46 @@ 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) => { + const affectedParents: Map = new Map() try { - const doc = $el.get(0).ownerDocument + let parent: JQuery | null = element - style = doc.createElement('style') - style.innerHTML = '* { scroll-behavior: inherit !important; }' - // there's guaranteed to be a