-
Notifications
You must be signed in to change notification settings - Fork 3.4k
perf: improve performance of pinning snapshots during hover / pin #32951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jennifer-shehane
wants to merge
20
commits into
develop
Choose a base branch
from
snapshot-reduce-get-computed-style
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+445
−118
Open
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 1cae27f
consolidate the 2 calls to getComputedStyles further
jennifer-shehane 4802b79
reduce call of this._contents
jennifer-shehane 9b17739
few other reduced _contents calls
jennifer-shehane 72a4112
fix tscheck error
jennifer-shehane b12787f
Update the other dimensions file in the driver (used for blackout)
jennifer-shehane da0dd95
optimize blackout a bit
jennifer-shehane 0eff22b
remove old todo
jennifer-shehane 1dc83bf
make further optimizations to performance
jennifer-shehane 4f8c8a2
write a dimensions test
jennifer-shehane 1d0d648
few more updates + tests
jennifer-shehane 6f1e276
Merge branch 'develop' into snapshot-reduce-get-computed-style
jennifer-shehane 8ada8ad
IMplement batching of offset and canceling of highlights
jennifer-shehane cd0735f
update test
jennifer-shehane 5037eab
changelog entry
jennifer-shehane 6690c4b
fix true/false race condition of highlighting cancellation
jennifer-shehane a0a5162
Merge branch 'develop' into snapshot-reduce-get-computed-style
jennifer-shehane 850f70a
Merge branch 'develop' into snapshot-reduce-get-computed-style
jennifer-shehane c761e8f
add body gaurd
jennifer-shehane 5ce3210
Merge branch 'develop' into snapshot-reduce-get-computed-style
jennifer-shehane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import { AutIframe } from './aut-iframe' | ||
| 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) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.