Skip to content
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

dependency: Update jQuery to latest #30345

Merged
merged 28 commits into from
Nov 4, 2024

Conversation

jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Oct 2, 2024

Additional details

Keeping the width/height patch we intended originally to remove

  • With the upgrade of jQuery to 3.2.0+ in dependency: Update jquery to 3.4.1 #29837, we needed to patch some of the jQuery 3.2+ logic on how they calculate height/width of elements in order to not introduce a breaking change.
  • In trying to remove the patch, it was discovered that the current way that jQuery calculates width/height is inconsistent across certain CSS models and certain browsers (mainly Firefox) [see issue], where it seems the intention from jQuery is to reverse these changes so that scrollbar-gutters are not ignored in width and height calculations in a 4.x version.
  • We will maintain the patch we previously had, so jQuery width/height calculations WILL DIFFER from Cypress's jQuery width/height calculations, but this will not in itself introduce a breaking change.

Bumping jQuery

This PR bumps jQuery to 3.7.1 which is latest. 4.0.0 of jQuery is still in Beta.

  • This means we can remove the patch logic around overriding the 'unload' event since this was fixed in jQuery 3.7.1 here.
  • Removed the $.find.matchesSelector override since $.find.support.matchesSelector is no longer available to set starting in jQuery 3.7.0. Instead, this logic was moved to a patch that now directly uses isUsingFocus to force the same behavior as before.
  • This may introduce some breaking changes to users, namely: jQuery changed their behavior in 3.5.0 to address an XSS security issue where they no longer fix incorrect DOM. Since we had some incorrect DOM structure in our visibility tests, this required updating or our tests would fail.

Steps to test

All tests should pass

How has the user experience changed?

PR Tasks

BREAKING: remove the patch that was preventing width/height calculation changes
@jennifer-shehane jennifer-shehane self-assigned this Oct 2, 2024
Copy link

cypress bot commented Oct 2, 2024

cypress    Run #58112

Run Properties:  status check passed Passed #58112  •  git commit c73de3dee5: Move changelog entry to 4.0
Project cypress
Branch Review remove-jquery-patch
Run status status check passed Passed #58112
Run duration 21m 25s
Commit git commit c73de3dee5: Move changelog entry to 4.0
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 6
Tests that did not run due to a developer annotating a test with .skip  Pending 1327
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 29364
View all changes introduced in this branch ↗︎
UI Coverage  46.24%
  Untested elements 188  
  Tested elements 166  
Accessibility  92.55%
  Failed rules  3 critical   8 serious   2 moderate   2 minor
  Failed elements 897  

@jennifer-shehane jennifer-shehane changed the title breaking: Remove patch of jQuery - updating width/height calculations for elements breaking: Update jQuery to latest Oct 8, 2024
@jennifer-shehane jennifer-shehane added the type: breaking change Requires a new major release version label Oct 8, 2024
@jennifer-shehane jennifer-shehane changed the title breaking: Update jQuery to latest dependency: Update jQuery to latest Oct 8, 2024
@jennifer-shehane jennifer-shehane added the Cypress 14 Issues scoped for Cypress 14 label Oct 9, 2024
@mschile mschile self-assigned this Oct 21, 2024
@@ -1419,29 +1419,45 @@ find.matches = function( expr, elements ) {
};

find.matchesSelector = function( elem, expr ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is essentially the same as below except instead of setting $.find.support.matchesSelector to false to force find being called, we now just directly check isUsingFocus to force the same behavior.

Comment on lines +40 to +41
cy.findByTestId('playground-selector').clear()
cy.findByTestId('playground-selector').type('[data-cy-root]')
Copy link
Member Author

Choose a reason for hiding this comment

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

just fixing chaining of a test that was found to match our recommendations

Comment on lines +544 to +545
// if not a sizzle or jQuery error, ignore it and let $el be null
if (!(sizzleRe.test(err.stack) || jQueryRe.test(err.stack))) throw err
Copy link
Member Author

Choose a reason for hiding this comment

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

jQuery no longer relies so much on sizzle, so these stack traces changed and are coming from jQuery now.

Comment on lines +31 to +39
// width or height of DOM in pixels
this.scrollableContainerWidthHeight = 500
this.elementWidthHeight = 100
this.scrollBarWidthHeight = 15

// divide by 2 to get the center
// browsers round up the pixel value so we need to round it
this.halfScrollPixels = Math.round((500 - 100) / 2)
this.halfScroll = Math.round((this.scrollableContainerWidthHeight - this.elementWidthHeight) / 2)
this.fullScroll = Math.round(this.scrollableContainerWidthHeight - this.elementWidthHeight)
Copy link
Member Author

Choose a reason for hiding this comment

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

Just cleaning this up to make these arbitrary numbers more understandable.

@@ -168,7 +168,7 @@ describe('src/cypress/dom/visibility', () => {
}

// ensure all tests run against a scrollable window
const scrollThisIntoView = add('<div style=`height: 1000px;` /><div>Should be in view</div>')
const scrollThisIntoView = add('<div style=`height: 1000px;`></div><div>Should be in view</div>')
Copy link
Member Author

Choose a reason for hiding this comment

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

jQuery no longer gracefully handles DOM that is not valid - so this would no longer create the accurate DOM to test against. This was just written wrong at some point.

Comment on lines 137 to +138
-function getWidthOrHeight( elem, dimension, extra ) {
+function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
+function augmentWidthOrHeight( elem, dimension, extra, isBorderBox, styles ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Putting the old width/height patch back into 3.7.1 code

@jennifer-shehane jennifer-shehane merged commit 8220c52 into release/14.0.0 Nov 4, 2024
82 of 83 checks passed
@jennifer-shehane jennifer-shehane deleted the remove-jquery-patch branch November 4, 2024 16:36
@jennifer-shehane jennifer-shehane mentioned this pull request Dec 3, 2024
28 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cypress 14 Issues scoped for Cypress 14 type: breaking change Requires a new major release version
Projects
Status: Building
Development

Successfully merging this pull request may close these issues.

4 participants