Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7373757
perf: reduce calls to getComputedStyles for element dimension calcula…
jennifer-shehane Nov 13, 2025
1cae27f
consolidate the 2 calls to getComputedStyles further
jennifer-shehane Nov 13, 2025
4802b79
reduce call of this._contents
jennifer-shehane Nov 13, 2025
9b17739
few other reduced _contents calls
jennifer-shehane Nov 13, 2025
72a4112
fix tscheck error
jennifer-shehane Nov 14, 2025
b12787f
Update the other dimensions file in the driver (used for blackout)
jennifer-shehane Nov 14, 2025
da0dd95
optimize blackout a bit
jennifer-shehane Nov 14, 2025
0eff22b
remove old todo
jennifer-shehane Nov 14, 2025
1dc83bf
make further optimizations to performance
jennifer-shehane Nov 14, 2025
4f8c8a2
write a dimensions test
jennifer-shehane Nov 14, 2025
1d0d648
few more updates + tests
jennifer-shehane Nov 14, 2025
6f1e276
Merge branch 'develop' into snapshot-reduce-get-computed-style
jennifer-shehane Nov 14, 2025
8ada8ad
IMplement batching of offset and canceling of highlights
jennifer-shehane Nov 14, 2025
cd0735f
update test
jennifer-shehane Nov 14, 2025
5037eab
changelog entry
jennifer-shehane Nov 14, 2025
6690c4b
fix true/false race condition of highlighting cancellation
jennifer-shehane Nov 14, 2025
a0a5162
Merge branch 'develop' into snapshot-reduce-get-computed-style
jennifer-shehane Nov 18, 2025
850f70a
Merge branch 'develop' into snapshot-reduce-get-computed-style
jennifer-shehane Nov 18, 2025
c761e8f
add body gaurd
jennifer-shehane Nov 18, 2025
5ce3210
Merge branch 'develop' into snapshot-reduce-get-computed-style
jennifer-shehane Nov 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _Released 11/18/2025 (PENDING)_
**Performance:**

- Limits the number of matched elements that are tested for visibility when added to a command log entry. Fixes a crash scenario related to rapid successive DOM additions in conjunction with a large number of elements returned from a query. Addressed in [#32937](https://github.com/cypress-io/cypress/pull/32937).
- Improved performance when viewing command snapshots in the Command Log. Element highlighting is now significantly faster, especially when highlighting multiple elements or complex pages. This is achieved by reducing redundant style calculations and batching DOM operations to minimize browser reflows. Addressed in [#32951](https://github.com/cypress-io/cypress/pull/32951).

**Features:**

Expand Down
140 changes: 140 additions & 0 deletions packages/app/src/runner/aut-iframe.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { AutIframe } from './aut-iframe'
Copy link
Member Author

@jennifer-shehane jennifer-shehane Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these are in an optimal form for unit tests, but it doesn't seem we have vitest or any other convention here but Cypress tests. I'd like to have a test for this, so welcome to if there's a better way to do this.

import { createEventManager } from '../../cypress/component/support/ctSupport'
import { getElementDimensions } from './dimensions'

describe('AutIframe._addElementBoxModelLayers', () => {
let autIframe: AutIframe
let mockGetComputedStyle: typeof getComputedStyle
let getComputedStyleCallCount: number
let mockJQuery: any

beforeEach(() => {
getComputedStyleCallCount = 0

mockGetComputedStyle = window.getComputedStyle
window.getComputedStyle = (element: Element, pseudoElement?: string | null) => {
getComputedStyleCallCount++

return mockGetComputedStyle.call(window, element, pseudoElement)
}

mockJQuery = (selector: any) => {
if (typeof selector === 'string') {
return {
get: (index?: number) => {
if (selector === 'body') {
return index === 0 ? document.body : [document.body]
}

return null
},
}
}

if (selector && selector.nodeType) {
return {
get: (index?: number) => {
return index === 0 ? selector : [selector]
},
}
}

return {
get: () => null,
}
}

const eventManager = createEventManager()

autIframe = new AutIframe('Test Project', eventManager, mockJQuery)
})

afterEach(() => {
window.getComputedStyle = mockGetComputedStyle
})

it('should not call getComputedStyle when dimensions are provided', () => {
const testElement = document.createElement('div')

testElement.style.width = '100px'
testElement.style.height = '50px'
testElement.style.padding = '10px'
testElement.style.border = '5px solid black'
testElement.style.margin = '15px'
testElement.style.position = 'absolute'
testElement.style.top = '20px'
testElement.style.left = '30px'
testElement.style.display = 'block'
testElement.style.transform = 'translateX(10px)'
testElement.style.zIndex = '100'
document.body.appendChild(testElement)

// Get dimensions first (this will call getComputedStyle once)
const dimensions = getElementDimensions(testElement)

// Verify dimensions include transform and zIndex
expect(dimensions.transform).to.exist
expect(dimensions.zIndex).to.exist

// Reset the counter since getElementDimensions also calls getComputedStyle
getComputedStyleCallCount = 0

const $el = mockJQuery(testElement)
const $body = mockJQuery('body')

// When dimensions are provided, _addElementBoxModelLayers should NOT call getComputedStyle
const container = (autIframe as any)._addElementBoxModelLayers($el, $body, dimensions)

// Verify getComputedStyle was NOT called in _addElementBoxModelLayers
// (it should use transform and zIndex from the provided dimensions)
expect(getComputedStyleCallCount).to.equal(0, 'getComputedStyle should not be called when dimensions are provided')

expect(container).to.exist
expect(container.classList.contains('__cypress-highlight')).to.be.true
expect(container.children.length).to.be.greaterThan(0, 'Should create at least one layer')

const layers = Array.from(container.children) as HTMLElement[]

layers.forEach((layer) => {
expect(layer.style.position).to.equal('absolute')
// Verify positions are stored in data attributes (not style properties)
expect(layer.getAttribute('data-top')).to.exist
expect(layer.getAttribute('data-left')).to.exist
expect(parseFloat(layer.getAttribute('data-top')!)).to.be.a('number')
expect(parseFloat(layer.getAttribute('data-left')!)).to.be.a('number')
expect(layer.getAttribute('data-layer')).to.exist
// Verify transform and zIndex were applied from dimensions
expect(layer.style.transform).to.equal('translateX(10px)')
expect(layer.style.zIndex).to.equal('100')
})

document.body.removeChild(testElement)
})

it('should call getComputedStyle only once when dimensions are not provided', () => {
const testElement = document.createElement('div')

testElement.style.width = '100px'
testElement.style.height = '50px'
testElement.style.display = 'block'
document.body.appendChild(testElement)

getComputedStyleCallCount = 0

const $el = mockJQuery(testElement)
const $body = mockJQuery('body')

// Call without providing dimensions (will call getElementDimensions internally)
const container = (autIframe as any)._addElementBoxModelLayers($el, $body)

// getElementDimensions will call getComputedStyle once and return transform/zIndex,
// so _addElementBoxModelLayers won't need to call it again
// We expect only 1 call total (from getElementDimensions)
expect(getComputedStyleCallCount).to.equal(1, 'Should call getComputedStyle only once in getElementDimensions')

expect(container).to.exist
expect(container.children.length).to.be.greaterThan(0)

document.body.removeChild(testElement)
})
})
Loading
Loading