Problem/Motivation
As mentioned in the parent issue #3238306: [META] Where possible, refactor existing jQuery uses to vanillaJS to reduce jQuery footprint, we are working towards reducing our jQuery footprint. One of the ways to accomplish this is to reduce the number of jQuery features used in Drupal core. We have added eslint rules that identify specific features and fail tests when those features are in use.
There are (or will be) individual issues for each jQuery-use eslint rule. This one is specific to jquery/no-attr, which targets the jQuery attr function.
Steps to reproduce
Proposed resolution
Remaining tasks
- In
core/.eslintrc.jquery.jsonChange"jquery/no-attr": 0,to"jquery/no-attr": 2,to enable eslint checks for uses of jQuery.attr(). With this change, you'll be able to see uses of the undesirable jQuery feature by runningyarn lint:core-js-passingfrom thecoredirectory - Add the following lines to
core/scripts/dev/commit-code-check.shso the DrupalCI testing script can catch this jQuery usage on all files, not just those which have changed
# @todo Remove the next chunk of lines before committing. This script only lints # JavaScript files that have changed, so we add this to check all files for # jQuery-specific lint errors. cd "$TOP_LEVEL/core" node ./node_modules/eslint/bin/eslint.js --quiet --config=.eslintrc.passing.json . CORRECTJQS=$? if [ "$CORRECTJQS" -ne "0" ]; then # No need to write any output the node command will do this for us. printf "${red}FAILURE ${reset}: unsupported jQuery usage. See errors above." STATUS=1 FINAL_STATUS=1 fi cd $TOP_LEVEL # @todo end lines to removeAdd the block about 10 lines before the end of the file, just before
if [[ "$FINAL_STATUS" == "1" ]] && [[ "$DRUPALCI" == "1" ]]; then, then remove it once all the jQuery uses have been refactored. - If it's determined to be feasible, refactor those uses of jQuery
.attr()to use Vanilla (native) JavaScript instead.
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | 3239161-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #26 | 3239161-nr-bot.txt | 9.11 KB | needs-review-queue-bot |
| #23 | 3239161-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-3239161
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #5
andy-blumComment #10
andy-blumComment #11
rahulrasgon commentedComment #12
rahulrasgon commentedBelow replacement needs to be done more.
Meanwhile can someone please review the MR :- https://git.drupalcode.org/project/drupal/-/merge_requests/5791#note_242353
Comment #13
rahulrasgon commentedComment #14
smustgrave commentedThe remaining task around the code-committ still seems needed.
Comment #15
nod_There are several places that create a jquery object just to get the original dom element after. We can get rid of the creation of the jQuery object and use the dom directly
Comment #17
gauravvvv commentedAddressed all feedbacks in MR. please review
Comment #18
smustgrave commentedChanges caused failures.
Comment #20
ahsannazir commentedIn the above raised MR, the Funtional Javascript test cases are failing and there are console errors as well
Comment #21
ahsannazir commentedResolved all failures. Please review
Comment #22
ahsannazir commentedComment #23
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #24
ahsannazir commentedComment #25
smustgrave commentedWill leave for sub-maintainer to review but personally find adding
[0]makes the readability go down.Comment #26
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #27
shubh_ commentedComment #28
smustgrave commentedIssues in MR.
Comment #30
Sam Phillemon commentedFixed the remaining MR-related issues.
Comment #31
smustgrave commentedFor good practice can the MRs be cleanup/hidden. There are currently 4 branche
Comment #35
shubh_ commentedDone
Comment #36
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #37
ahsannazir commentedComment #38
bnjmnmComment #39
ahsannazir commentedComment #40
bnjmnmComment #41
ahsannazir commentedComment #42
smustgrave commentedMR needs a manual rebase
Comment #43
ahsannazir commentedComment #44
nod_First of all thank you all for the hard work on this one, I've had to push a number of patches like this and I know how hard it is to keep up.
I'm going to try and refocus the jQuery removal work and to do that I need to take a few decisions. I'm going to close this issue for a few reasons:
There is one line to change and just noticed a bug (jQuery doesn't have a forEach method)
I ported the credits to #3464044: Credit for work on the reduce jQuery issues, which I will mark as fixed as soon as I go through all the others impacted jQuery issues.