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-serialize, which targets the jQuery serialize function.
Steps to reproduce
Proposed resolution
Remaining tasks
- In
core/.eslintrc.jquery.jsonChange"jquery/no-serialize": 0,to"jquery/no-serialize": 2,to enable eslint checks for uses of jQuery.serialize(). 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
.serialize()to use Vanilla (native) JavaScript instead.
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3238922
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 #8
omkar-pd commentedRemoved uses of serialize(). The target branch needs to be changed from 9.3.x to 11.x.
Comment #9
omkar-pd commentedAttaching a patch as well.
Comment #10
smustgrave commentedMR is pointing to 9.3.x, needs to point to 11.x
FYI attaching patches + MRs is discouraged if people need an MR they can can down the diff.
Thanks!
Comment #11
omkar-pd commentedYes, I was not able to change the target branch and also was not able to create a new branch. so added a patch.
Comment #13
omkar-pd commentedAll tests are passed for MR 5777.
Changing this to Needs Review.
Comment #15
smustgrave commentedSince it's only replacing the one function, easy enough to review.
Applied the MR and submitted a node form, not sure how well to test.
Comment #17
catchCommitted/pushed to 11.x (which will also become 10.3.x soon), thanks!