If you click on add to shortcut multiple times(before the yellow start appears), will add multiple shortcuts of the same item

Steps to reproduce

Click on the Add to shortcut multiple times, will create multiple shortcut(provided, click should be made continuously)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Upchuk’s picture

Assigned: Unassigned » Upchuk
Upchuk’s picture

Assigned: Upchuk » Unassigned
tstoeckler’s picture

Version: 8.0.0-beta2 » 8.0.x-dev

Wow, nice find!

sidharthap’s picture

FileSize
70.48 KB

In my case, The message shows once but when I navigate to shortcut set it seems multiple times added.
It should validate the path prior to add.

Thanks

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jibran’s picture

Title: Shortcut is being added multiple times » Clicking 'Add to shortcuts' adds shortcut multiple times

The quick fix would be to add JS to the 'Add to shortcuts' link and disable it once it's clicked. A complete fix would be to not allow adding the same link twice to the shortcut set. I think we should add JS in this issue and UniqueShotcutValidator to the Shortcut entity in a follow-up.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Issue tags: -shortcut

The quick fix would be to add JS to the 'Add to shortcuts' link and disable it once it's clicked. A complete fix would be to not allow adding the same link twice to the shortcut set. I think we should add JS in this issue and UniqueShotcutValidator to the Shortcut entity in a follow-up.

I think that's a good start. This will be really hard to test though. So I don't think a test will be needed.

Removing the shortcut issue tag.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Upchuk’s picture

Version: 8.6.x-dev » 8.7.x-dev
Status: Active » Needs review
FileSize
605 bytes

So the problem with this is actually pretty simple.

The drupal.form library provides already the functionality for preventing multiple submits in one go. And all core entity forms attach their own JS libraries which in turn depend on this. But shortcut does not. So this is why it's not happening on other entity types.

So the patch is really simple. But yeah, not sure how to test this, other than just checking the library is on the page. Not seeing how this logic is tested elsewhere.

Attached the patch that fixes it.

jibran’s picture

Issue tags: +Needs tests

Nice! let's add some tests.

Upchuk’s picture

@jibran, like it was discussed, testing is very difficult for this. Moreover, the original logic that applies to all other forms was committed without any testing. See #1705618: Double click prevention on form submission

Any suggestions?

jibran’s picture

@Upchuk when that issue was committed 5 years ago in #1705618-42: Double click prevention on form submission we didn't have JS tests in core. Now we can write two types of JS test, one written in PHP and other in JS.
This is a behavioral bug so the way the user is interacting with the site is wrong. I think we can mimic multiple clicks using JS tests or at least try. :)

Upchuk’s picture

@jibran ok, but then clearly testing this does not belong in the shortcut module. The test for this is a core test that deals with the generic form logic that prevents multiple submissions. So it is outside the scope of this issue I think. No?

jibran’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests +Needs followup

I asked @larowlan for second opinion on #17, let's create a follow-up.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: 2370115-13.patch, failed testing. View results

jibran’s picture

Status: Needs work » Reviewed & tested by the community

Fail seems unrelated so back to RTBC.

Upchuk’s picture

alexpott’s picture

Why don't all forms automatically have this added. I guess it's to have no javascript pages since this would add quite a bit of JS...

drupal.form:
  version: VERSION
  js:
    misc/form.js: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/drupal.debounce
    - core/jquery.cookie
    - core/jquery.once

The weird thing is that by default I'd want Drupal to do the multiple submission protection and have a way for forms to opt out of this.

Upchuk’s picture

@alexpott Yeah, I agree. Maybe the js can be moved to another library that only contains that small bit and then added across all the forms. But let's talk about this in the followup ticket I opened where we should also test this: #3015264: Tests for double click prevention on form submission

catch’s picture

Version: 8.7.x-dev » 8.6.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed edfd5bbeae to 8.7.x and 30fcc3ca95 to 8.6.x. Thanks!

  • catch committed edfd5bb on 8.7.x
    Issue #2370115 by Upchuk, nafsinvk, jibran: Clicking 'Add to shortcuts'...

  • catch committed 30fcc3c on 8.6.x
    Issue #2370115 by Upchuk, nafsinvk, jibran: Clicking 'Add to shortcuts'...

Status: Fixed » Closed (fixed)

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

eleleka’s picture