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-animate, which targets the jQuery animate function.

Steps to reproduce

Proposed resolution

Remaining tasks

  • In core/.eslintrc.jquery.json Change "jquery/no-animate": 0, to "jquery/no-animate": 2, to enable eslint checks for uses of jQuery .animate(). With this change, you'll be able to see uses of the undesirable jQuery feature by running yarn lint:core-js-passing from the core directory
  • Add the following lines to core/scripts/dev/commit-code-check.sh so 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 remove

    Add 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 .animate() to use Vanilla (native) JavaScript instead.

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#20 3239139-nr-bot.txt1.45 KBneeds-review-queue-bot

Issue fork drupal-3239139

Command icon 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

Theresa.Grannum created an issue. See original summary.

bnjmnm made their first commit to this issue’s fork.

nod_’s picture

Possibly need to add a depreciation notice here for dynamic uses of animate (and other jQuery methods)
https://git.drupalcode.org/project/drupal/-/blob/9.3.x/core/misc/ajax.es...

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

shubh_’s picture

Status: Active » Needs work

I am working on this issue...

shubh_’s picture

Status: Needs work » Needs review
nod_’s picture

Status: Needs review » Needs work
shubh_’s picture

ok, will check that

shubh_’s picture

Status: Needs work » Needs review

Updated as per feedback..

nod_’s picture

Status: Needs review » Needs work

Thanks for the update but I don't think we understood each other, the goal is to replace jquery with native capabilities so if we need a 20 line function to replicate jQuery functionality it's not worth it.

Here I think we can replace the calls to .animate with the native .scrollTo() without a new function that does the animation.

shubh_’s picture

Status: Needs work » Needs review

Addressed the feedback..

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe @nod_ feedback has been addressed on this one.

nod_’s picture

Status: Reviewed & tested by the community » Needs work

small change required

shubh_’s picture

Status: Needs work » Needs review

Addressed the change..

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.45 KB

The 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.

shubh_’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Leaning into that @nod_ has reviewed this one already. But feedback appears to be addressed.

alexpott changed the visibility of the branch 3239139-refactor-if-feasible to hidden.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Added a comment to the MR.

shubh_’s picture

Status: Needs work » Needs review

Updated MR with suggestion...

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Appears comment has been removed.

nod_’s picture

Status: Reviewed & tested by the community » Needs work

Regression when a pager is in a modal (like for the media library view), see MR comment. Do not just apply the suggestion, the whole block of code needs to be optimized, see MR comment.

shubh_’s picture

Status: Needs work » Needs review

Addressed the feedback given

shubh_’s picture

Updated the issue feedbacks

nod_’s picture

nod_’s picture

shubh_’s picture

The second commit has double $ thats why was refactored in second commit

Btw this converting of scrollTarget to jquery failing the test cases

shubh_’s picture

@nod_ all feedbacks resolved here, pls review it

nod_’s picture

thanks, that works, we can always improve later if needed, not breaking stuff is more important :)

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Going to lean on nod_ review for this one

  • nod_ committed 449f6fbf on 11.x
    Issue #3239139 by shubh_, Theresa.Grannum, alexpott: Refactor (if...

  • nod_ committed da42dc3b on 10.3.x
    Issue #3239139 by shubh_, Theresa.Grannum, alexpott: Refactor (if...

nod_’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 449f6fb and pushed to 11.x. Thanks!

  • nod_ committed 93d269d5 on 10.3.x
    Revert "Issue #3239139 by shubh_, Theresa.Grannum, alexpott: Refactor (...
nod_’s picture

Status: Fixed » Needs work

failing on 10.3.x because of asset size test

shubh_’s picture

so what needs to do here can you pls guide ?

alexpott’s picture

We need to fix the two test fails here... https://git.drupalcode.org/project/drupal/-/pipelines/150084/test_report...

It'll just be a case of changing numbers...

nod_’s picture

I'll take care of it, thanks :)

nod_’s picture

Status: Needs work » Needs review

nod_’s picture

Status: Needs review » Reviewed & tested by the community

green

  • nod_ committed 654d7321 on 10.3.x
    Issue #3239139 by shubh_, Theresa.Grannum, alexpott: Refactor (if...
nod_’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.