Skip to content

Commit 9f0e71f

Browse files
chore: Update styles in runner to not be fractional + only update scrollbar style if value has changed (#32437)
* chore: set debug verbose on stderr-filtering logs * fix: spike into resize observer fix * only commit resizeobserver protection * prevent fractional numbers in iframe styles * some other changes * undo irrelevant changes * undo verbose * remove console
1 parent a07062d commit 9f0e71f

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,27 @@ describe('Cypress In Cypress E2E', { viewportWidth: 1500, defaultCommandTimeout:
3737
cy.get('.hook-open-in-ide').should('exist')
3838

3939
cy.get('#unified-runner').then((el) => {
40-
expect(el[0].getAttribute('style')).to.match(/width: 1000px; height: 660px; transform: scale\(0.854\d+\); position: absolute; margin-left: -25px;/)
40+
expect(el[0].getAttribute('style')).to.match(/width: 1000px; height: 660px; transform: scale\(0.85\); position: absolute; margin-left: -25px;/)
41+
expect(el[0].getBoundingClientRect().width).to.equal(1000 * 0.85)
42+
expect(el[0].getBoundingClientRect().height).to.equal(660 * 0.85)
43+
expect(parseInt(el[0].style.marginLeft)).to.equal(-25)
44+
})
45+
})
46+
47+
it('demonstrates fractional dimension calculations before rounding fixes', () => {
48+
cy.viewport(1333, 777)
49+
cy.visitApp()
50+
cy.specsPageIsVisible()
51+
cy.contains('dom-content.spec').click()
52+
cy.waitForSpecToFinish()
53+
54+
cy.get('[data-model-state="passed"]').should('contain', 'renders the test content')
55+
cy.findByTestId('aut-url').should('be.visible')
56+
57+
cy.get('#unified-runner').then((el) => {
58+
const style = el[0].getAttribute('style')
59+
60+
expect(style).to.match(/width: 1000px; height: 660px; transform: scale\(0\.78\); position: absolute; margin-left: -108px;/)
4161
})
4262
})
4363

packages/app/src/runner/useRunnerStyle.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export const useRunnerStyle = () => {
7272
scale = Math.min(containerWidth.value / autStore.viewportDimensions.width, containerHeight.value / autStore.viewportDimensions.height, 1)
7373
}
7474

75-
return scale
75+
// Round scale to prevent fractional dimensions
76+
return Math.round(scale * 100) / 100 // Round to 2 decimal places for clean fractions
7677
})
7778

7879
const viewportStyle = computed(() => {
@@ -81,8 +82,8 @@ export const useRunnerStyle = () => {
8182
// see this issue for details: https://github.com/cypress-io/cypress/issues/21881
8283

8384
let style = `
84-
width: ${autStore.viewportDimensions.width}px;
85-
height: ${autStore.viewportDimensions.height}px;
85+
width: ${Math.round(autStore.viewportDimensions.width)}px;
86+
height: ${Math.round(autStore.viewportDimensions.height)}px;
8687
transform: scale(${scale.value});
8788
position: absolute;
8889
`
@@ -91,7 +92,7 @@ export const useRunnerStyle = () => {
9192
// viewport with midpoint and the the container width midpoint and apply a negative margin
9293
if (!screenshotStore.isScreenshotting) {
9394
style += `
94-
margin-left: ${(containerWidth.value / 2) - (autStore.viewportDimensions.width / 2) }px`
95+
margin-left: ${Math.round((containerWidth.value / 2) - (Math.round(autStore.viewportDimensions.width) / 2)) }px`
9596
}
9697

9798
return style

packages/app/src/specs/SpecsList.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ useResizeObserver(containerProps.ref, (entries) => {
408408
if (containerElement) {
409409
const displayedScrollbarWidth = containerElement.offsetWidth - containerElement.clientWidth
410410
411-
scrollbarOffset.value = displayedScrollbarWidth
411+
// Only update if the value actually changed to prevent unnecessary updates
412+
if (scrollbarOffset.value !== displayedScrollbarWidth) {
413+
scrollbarOffset.value = displayedScrollbarWidth
414+
}
412415
} else {
413416
scrollbarOffset.value = 0
414417
}

0 commit comments

Comments
 (0)