Problem/Motivation
As part of #3094468: [plan] Update core JavaScript (and CSS) dependencies prior to 9.0.0-beta1 we need to update modernizr.
Proposed resolution
Update it
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | interdiff__34-38.txt | 2.76 KB | bnjmnm |
| #38 | 3100937-38.patch | 15.32 KB | bnjmnm |
| #34 | 3100937-34.patch | 16 KB | bnjmnm |
| #34 | interdiff_31-34.txt | 1.32 KB | bnjmnm |
| #31 | 3100937-31.patch | 15.3 KB | bnjmnm |
Comments
Comment #2
tedbowI first tried to update it via the web tool from the link in the core file http://modernizr.com/download/?-details-inputtypes-touchevents-addtest-p...
This produces a 3.6.0 version for some reason.
Then followed the instructions here https://modernizr.com/docs
and used the same url above but downloaded the "Command Line Config" to build it locallly.
Following the instructions I did
This produced a modernizr.js file that renamed to modernizr.min.js
I will upload the json config file also
Comment #3
tedbowComment #5
tedbowThis may actually be test problem. Looking at 1 of the failing tests
\Drupal\Tests\field_ui\FunctionalJavascript\ManageDisplayTest::testFormatterUIIf I comment this out and use
To pause the test and then drag it manually. Then resume the test. The test passes.
\Behat\Mink\Driver\Selenium2Driver::dragTo()creates it's own JS which might be what is failing to do the drag.Comment #6
tedbowI also tried the method above to pause the test after
\Behat\Mink\Driver\Selenium2Driver::dragTo()is called. I then looked at the test chrome browser to see if there were any javascript console errors but there weren'tI also updated sortable.js to 1.10.1 which we need to do for #3094468: [plan] Update core JavaScript (and CSS) dependencies prior to 9.0.0-beta1 since it is involved in tabledrag. This didn't help.
Comment #7
bnjmnmThere's logic in
Drupal.tableDrag.prototype.findDropTargetRowthat uses coordinates and row height to determine if a dragged row is in a new target regionif (y > rowY - rowHeight && y < rowY + rowHeight)Debugging
\Drupal\Tests\field_ui\FunctionalJavascript\ManageDisplayTest::testFormatterUI, I found that the values of the variables in this conditional are different with Modernizr 3.8.0. They are close enough that it's still possible to manually drag a row into a new position. However, these different values are not enough to trigger a new position for the pointer distance covered bydragTo()Values in testFormatterUI with Modernizr 3.3.1
Values in testFormatterUI with Modernizr 3.8.0
Looking into what may be causing this difference.
Comment #8
bnjmnmThe test failure in
LayoutBuilderDisableInteractionsTest::testFormsLinksDisabledcan be reproduced manually.Not yet sure why this is the case, but the steps to reproduce are specific enough to suggest there may be a fairly specific answer awaiting us.
Comment #9
bnjmnmLooks like this is due to
Modernizr.toucheventsreturning different results than 3.3.1 than 3.8. Will investigate solutions.Comment #10
bnjmnmIn 3.7.1,
Modernizr.toucheventsaddedwindow.TouchEventas one of the ways of determining if a browser supports touchevents. This results in far fewer instances of.no-touchevents(perhaps none?) and is the reason the tests are failing.The touchevents test is deprecated in Modernizr 3.8 and will be removed in 4.0, so it may be worth refactoring out of this particular test anyway
Comment #11
bnjmnmThis addresses the test failures, which were due to changes in Modernizr's touchevents test. This is a problem others have experienced: https://github.com/Modernizr/Modernizr/issues/2431 , and it will not be fixed as the touchevents test is already deprecated and will be removed in 4.0.
To fix this, I created a Modernizr build that did not include touchevents, but added two options (mq and prefixes) that would make it possible to recreate the touchevents test as a custom addition. This otherwise matches the configuration of the 3.3.1 build previously used in core.
This is the build command I used:
./bin/modernizr -f details,inputtypes -o addTest,prefixed,setClasses,testStyles,mq,prefixes -d ./modernizr.min.js -uNo interdiff since this is not based on the previous patch.
Comment #13
bnjmnmPatch #11 did not include the compiled
modernizr-additional-tests.jsthis fixes that.Comment #14
tedbowThis URL is in the JS so someone could rebuild this like when we need to upgrade.
Is this the same as the build comment above? If not how will someone know to do the specific build in the future?
I don't think it is clear that the Modernizr we have included in core doesn't include touchevents. When I read this before before reading explanation in the last comment on this issue I didn't get that. We should make this very clear.
is this something we should also deprecate?
Comment #15
tedbowComment #16
bnjmnmRe #14
⓵
That's something should have mentioned. That URL will download Modernizr with the correct config... BUT, it will be a custom build of version 3.6.0, not the most recent. In order to create a build with Modernizr 3.8.0, I had to do it locally.
⓶
Yea I had a little trouble explaining this well. Lets see if this patch improves it and I'll keep iterating until it makes sense.
⓷
Yea probably, I tagged with Needs Followup and will take care of that. It's been deprecated from Modernizr because of how frequently developers misunderstand what it detects, but there's currently no issue with the actual functionality, so it's not horribly urgent at the moment https://github.com/Modernizr/Modernizr/pull/2432
But since it's no longer supported, there is the risk of this being out of sync with newer browsers that may have different indicators of touch support.
Comment #17
bnjmnmCreated followup #3101922: Find replacement for Modernizr touchevent test and deprecate
Comment #18
bnjmnmSome info to help with testing of the modifications of Modernizr's
toucheventstest.When Modernizr is loaded on a this test will either add
.toucheventsor.no-toucheventsto<html>. The best way to confirm there are no regressions in the patch is manually test as many scenarios/devices as possible and confirm that.touchevents/.no-toucheventsis added the same pre-patch and post-patch. Note that Chrome's mobile device simulator is recognized by Modernizr as supportingtouchevents, while in normal desktop mode it adds.no-touchevents.If testing with a device that doesn't offer easy access to html source, the behavior can be tested by using a feature impacted by CSS rules using
.toucheventsor.no-touchevents, but it may be easiest to temporarily add easily-identifiable CSS rules based on those classes.Comment #19
tedbowI reviewed the 3.8.0 version of this in Modernzer https://github.com/Modernizr/Modernizr/blob/v3.8.0/feature-detects/touch... and changes are explained comment above which make sense
I also also looked that release 3.7.0 https://github.com/Modernizr/Modernizr/blob/v3.7.0/feature-detects/touch... which was before
window.TouchEventwas added and that was the only difference besides formatting from 3.8.0It acts the same as 9.0.x. When I am in Chrome mobile device simulator and reload the page .touchevents class is added. In regular chrome .no-touchevents is added.
When using the patch if I remove
modernizr-additional-tests.es6.jsfrom the library neither class gets added so I could be sure this was coming from this file.Comment #20
lauriiiShould we asses whether we should do this in a follow-up?
I spent a while figuring out what this code does. What it essentially does is it generates a bunch of media queries that could theoretically result in detecting whether the users' device has touch-enabled or not, but AFAIK this isn't supported by any browsers. The 'heartz' is added in the end just for the sake of having something to end the list because otherwise, this would end with
'(which would make this an invalid media query. Let's add an inline comment explaining this.Comment #21
bnjmnmPatch addresses the two items in #20
Comment #23
jungleNo newline at end of file
Comment #24
jungleTests passed with php7.3
Comment #25
bnjmnmRe #23 - no newline at the end of the file is expected, that is how the file is provided by Modernizr.
Re #24 - this should be still set back to "Needs review" since the test failure is an unrelated test that is known to intermittently fail. It shouldn't have been set back to Needs Review because it passed on PHP 7.3 and not 7.2. Tests need to pass on all supported PHP versions. The intermittently-failing Media Library tests may have made that confusing.
Comment #26
tedbow#21 looks good!
Comment #27
lauriiiSorry, my comment on #20.1 was confusing. I tried to suggest there to remove all changes to the logic from this patch and move them to separate follow-ups so that they can be reviewed appropriately.
Comment #28
bnjmnm#27 makes sense. Updated the test so it's a copy of 3.3.1 with no logic changes.Since this test will need to ultimately be replaced, I think any following up can happen when the test is replaced in #3101922: Find replacement for Modernizr touchevent test and deprecate as opposed to updating the logic within it.
Comment #29
lauriiiThis looks good. Marking this as RTBC. I've tested manually on Chrome that touchevents are recognized correctly, but given that this has lots of cross browser compatibility concerns, this isn't enough to validate that the code is correct. Therefore, I simply compared the code with https://github.com/Modernizr/Modernizr/blob/v3.3.1/feature-detects/touch... and it seems to be exactly the same.
Any thoughts on adding a @see comment referring to https://github.com/Modernizr/Modernizr/blob/v3.3.1/feature-detects/touch...?
Nit: This new line is unnecessary (can be fixed on commit).
Comment #30
xjmLet's address both points in #29. Thanks!
Comment #31
bnjmnmAddresses #29
Comment #32
xjm#31 is small enough that I don't think we need another peer review. :)
Updating issue credit...
Comment #33
xjmGiven the manual testing documented in #8, #18, #19, and #29 I think this is ready!
...except that I get the following errors when trying to commit this:
Since the test is copied from an upstream test, I wonder if we need to simply mark it as a file to skip linting?
Comment #34
bnjmnmAddresses #33 by bypassing a single eslint rule in the test's conditional statement.
Comment #35
lauriiiMore nitpicky feedback on the patch 🧐
I don't think we have actual coding standard on this but we've definitely standardized on adding space before and after the opening and the closing objects.
I would consider adding a parameter to the closure for passing these since it shouldn't interfere with functionality in any way.
Nit: We might want to consider making this comply with the 80 characters per line coding standard.
We should revert this change. Can be done on commit.
Comment #36
xjmShould we actually be making coding standards fixes on the test? Since it's copied from upstream.
Comment #37
bnjmnmAddresses #35
Item 2 was addressed by changing
document instanceof DocumentTouchtodocument instanceof window.DocumentTouchafter visiting the instanceof spec to be sure it was fine. Simply adding it to the closure wasn't passing linting and although it could certainly be made to work, this could be done with fewer changes and it's more readable.It's actually not possible to work with an exact copy of Modernizr's test due to some variables not being in the same scope when a test is added outside of Modernizr. If it needs a few changes anyway, I see the benefit of fully adopting Drupal's JS code standards as well. Fortunately, it's a simple enough test that a reviewer can confirm that it is still functionally identical.
Comment #38
bnjmnmOops, here is the patch.
Comment #39
xjmThe downside as I see it is that if Modernizr further updates the test, we can't diff easily to apply their changes to our test.
Comment #40
bnjmnmThere's a few reasons why this doesn't strike me as a concern:
(this isn't a hill I need to die on, btw 🙂)
Comment #41
xjmOK, sounds like fair reasoning to me.
Comment #42
lauriiiLooks like #38 addresses all of my feedback and #40 addresses concerns raised by @xjm on #39. Thank you @bnjmnm! 👏
Comment #44
xjmCommitted and pushed to 9.0.x. Thanks!