Closed (fixed)
Project:
Drupal core
Version:
8.8.x-dev
Component:
javascript
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
7 Oct 2019 at 21:13 UTC
Updated:
30 Oct 2019 at 19:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
zrpnrThe domready library is only used in one file:
drupal.init.js. I wrote a function to replace it based on domready itself, the example from http://youmightnotneedjquery.com/ for "ready", and the MDN doc listed in the IS.If the document.readyState is not loading it fires immediately, otherwise it adds a listener for
DOMContentLoaded, the same event domready is listening for. After the event the listener gets removed.I was curious about
hack = doc && doc.documentElement.doScrollhttps://github.com/ded/domready/blob/master/ready.js
which seems to be meant to work for IE8-10, so it should be safe to remove for this replacement.
The tests in
AttachedAssetsTestare checking that assets are attached correctly, I'm not sure if there are other good asset libraries that could be tested instead here. For example intestHeaderHTMLit was the example of an "indirect dependency".I'm also not clear on the consequences of removing it from hook_page_attachments, because it is an API function.
Comment #4
zrpnrI discussed this with @lauriii in slack and he suggested exposing the replacement function as a global so that it could be used elsewhere.
This patch moves and renames the function so it is added to
DrupalComment #5
lauriiiLet's keep this in but let's switch to another library. This is just example code for documentation.
Maybe we should make the
common_test/js-headerdepend on another library that has nested dependencies?Comment #6
zrpnr#5.1 I restored these lines, and used
drupalSettingsas the example.The JS asset of the indirect dependency (core/domready) of common_test/js-header appears in the header.#5/2 If I'm understanding this test assertion correctly,
drupalSettingsis also a good candidate here since it is a dependency ofcore/drupalwhich is the only dependency ofcommon_test/js-headerComment #7
lauriiiNice 👍
Double checked that the event is supported by Drupals supported browser. Looks all good: https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded...
We don't have any explicit test coverage for this but that's probably fine since if this doesn't work, most Drupal behaviors will be broken.
Given the implications of this not working, it would be probably good to do a bit of manual testing on this across our supported browsers. Other than that, this looks good.
Comment #8
nod_Couple of things.
As is the Drupal.domready is not overridable. We define it in the file then immediately use it, there is no chance for anything else to override the function. if we want to make it overridable the definition of Drupal.domready needs to be in a separate file like the current domready lib.
Usually we declare everything inside the closure so Drupal.domReady sould be inside the closure.
The domready lib can handle several callbacks, whereas this version can't.
Given that I'd be up to not make the domready thing overridable and just go with how #2 declares a onReady function inside the closure. It's simply a way to trigger behaviors which are what should be used to do things anyway.
Comment #9
zrpnrMade another version of #6 using the function from #2.
Comment #10
nod_Thanks, ok for me now.
Comment #11
lauriiiGood catch! 👍Thank you @nod_!
Comment #12
zrpnrI tested this manually with crossbrowsertesting.com, that service can take screnshots of a given url.
It has additional browsers available for "live" tests so some of the less common ones were possible to test here too, like opera mini and mobile.
I used ngrok to make a public url for my localhost, then I loaded the
core/drupallibrary withhook_page_attachments_alterso it would load on an anonymous front page view.and inside the callback function I added test code to change a page element red so it would be easy to see in the screenshot.
All of these screenshots show the red background, indicating that the domReady function executed the callback.
The browsers I checked against came from browerslist, run
npx browerslistin the core folder to have it read the list in package.jsonThere are more here than listed in Drupal's current browser requirements
Tested
chrome 77 - tested manually on OSX
chrome 76 - Mac_OSX_10.14_Google_Chrome_76_(64-bit)_1024x768_window.png
chrome 75 - Mac_OSX_10.11_Google_Chrome_75_(64-bit)_1366x768_window.png
chrome 74 - Mac_OSX_10.11_Google_Chrome_74_(64-bit)_1366x768_window.png
edge 18 - Windows_10_Microsoft_Edge_18_1024x768_window.png
edge 17 - Windows_10_Microsoft_Edge_17_1024x768_window.png
firefox 69 - Mac_OSX_10.14_Firefox_69_1366x768_window.png
firefox 68 - Mac_OSX_10.14_Firefox_68_1024x768_window.png
firefox 60 - Mac_OSX_10.13_Firefox_60_1366x768_window.png
safari 13 - tested manually on OSX
safari 12.1 - Mac_OSX_10.14_Safari_12_1024x768_window.png
ie 11 - Windows_10_Internet_Explorer_11_1024x768_window.png
opera 62 - tested Opera 63 - Windows_10_Opera_63_1366x768_window.png
opera 60 - Mac_OSX_10.14_Opera_60_1366x768_window.png
and_chr 76 - tested android chrome 75 - Android_Galaxy_S8_8.0_Chrome_Mobile_75_1080x2220_window.png
and_ff 68 - Android_Galaxy_S9_Firefox_mobile_68.png
and_uc 12.12
ios_saf 13 - tested on iPhone
ios_saf 12.0-12.1 iPad_6th_Gen_Simulator_Mobile_Safari_12.0_2732x2048_window.png
op_mini all - tested opera mini 32 - Nexus_9_Opera-mini_32.png
op_mob 46 - tested opera mobile 44 - Nexus_9_Opera_mobile_44.png
samsung 9.2 - Galaxy_S8_Samsung_9.2.png
samsung 8.2 - Galaxy_S6_Samsung_6.2.png
Not tested
ios_saf 12.2-12.3 - but should be covered by testing the older version
android 76 - not sure what this refers to
and_qq 1.2 - QQ browser
baidu 7.12 - did not install Baidu, but it is based on chromium
ie_mob 11 - not available for testing
kaios 2.5
Comment #13
lauriiiAwesome! Thanks for testing the patch manually on a broad range of browsers!
After this has been committed, we could update the change record to link to a Gitlab page of this file to show this function so that people who need this, could copy it from there.
The code itself looks good. The deprecation message links to the correct change record and the replacing function looks fine. It has been also reviewed by @nod_ who is a JavaScript subsystem maintainer. Moving to RTBC and tagging with needs release manager review. 👏
Comment #17
xjmCommitted and pushed to 9.0.x, 8.9.x, and 8.8.x, and published the change record. Thanks!
Comment #18
xjmI didn't quite follow the updates that were to be made to https://www.drupal.org/node/3086669 but I think they probably involve putting in the name of the new function and linking it to the source code?
Comment #19
lauriii@xjm I updated the change record with what I thought at the time of writing that comment. We can't really reference to a function name because it's just a local variable.