Problem/Motivation

I had this problem with v8.0.6 as well. Installed 8.1.0 for a test and I'm still having problems adding a new filter group to a View.

Steps to reproduce the bug:
1- Log as admin;
2- Go to Structure->Views;
3- Choose any view to edit;
4- In the filter cryteria area, click 'add/ or rearrange' button;
5- Click the link to create a new filter group;
6- For less than a second the new group appears, but the dialogue closes abruptly;

The problem is that the form is submitted twice. It sometimes works, and sometimes not.

The random failures can be explained with the following: Currently, the click on the add button triggers 2 AJAX calls to the server (in this order):

  1. A correct one with a triggering element. This respons will add a filter group
  2. An incorrect one without a triggering element. This respons will not change anything in the form.

If the second request finishes last, the form doesn't contain the new filter group.

Proposed resolution

Prevent the double submit and make sure the add and remove buttons work normally.

Remaining tasks

- Write test (done)
- Write patch (done)

User interface changes

-

API changes

-

CommentFileSizeAuthor
#43 view_ui_filter_group-2717629-43.patch4.24 KBmichielnugter
#43 interdiff-42-43.txt2 KBmichielnugter
#42 view_ui_filter_group-2717629-42.patch4 KBmichielnugter
#42 interdiff-38-42.txt1.53 KBmichielnugter
#38 view_ui_filter_group-2717629-38.patch3.72 KBmichielnugter
#38 interdiff-35-38.txt1.39 KBmichielnugter
#35 view_ui_filter_group-2717629-35.patch2.69 KBmichielnugter
#35 interdiff-34-35.txt555 bytesmichielnugter
#34 view_ui_filter_group-2717629-34.patch2.59 KBmichielnugter
#34 interdiff-28-34.txt421 bytesmichielnugter
#28 view_ui_filter_group-2717629-28.patch2.09 KBLendude
#22 view_ui_filter_group-2717629-22.patch2.32 KBLendude
#22 interdiff-2717629-18-22.txt840 bytesLendude
#22 after add click.png80.96 KBLendude
#18 view_ui_filter_group-2717629-18.patch2.27 KBLendude
#18 interdiff-2717629-16-18.txt1.57 KBLendude
#16 view_ui_filter_group-2717629-16.patch2.41 KBLendude
#16 interdiff-2717629-14-16.txt842 bytesLendude
#14 view_ui_filter_group-2717629-14.patch2.32 KBLendude
#14 interdiff-2717629-1-14.txt1.64 KBLendude
#3 view_ui_filter_group.patch1.83 KBdroplet
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ismael.rm created an issue. See original summary.

droplet’s picture

Component: javascript » views.module
Assigned: ismael.rm » Unassigned
Priority: Normal » Major
Issue tags: +JavaScript

Confirmed. Moved to View thread to see if any duplicated reports.

droplet’s picture

droplet’s picture

Status: Active » Needs review

Trigger testbot run

Status: Needs review » Needs work

The last submitted patch, 3: view_ui_filter_group.patch, failed testing.

catapipper’s picture

Issue tags: -JavaScript +JavaScript neworleans2016
catapipper’s picture

Issue tags: -JavaScript neworleans2016 +JavaScript, +neworleans2016

Triaging at DrupalCon New Orleans 2016

catapipper’s picture

Triaged with @dbyers55.

Steps to reproduce are well documented. No duplicate issues were found. Issue is still relevant but needs more work. The patch is adding a JavascriptTestBase class for future testing of the issue. Reproduced in 8.2.x.

dbyers55’s picture

Issue tags: +Triaged for D8 major current state
xjm’s picture

Thanks @catapipper and @dbyers55 for helping triage this issue! (Updating issue credit to include triagers.)

vprocessor’s picture

Assigned: Unassigned » vprocessor

The last submitted patch, 3: view_ui_filter_group.patch, failed testing.

The last submitted patch, 3: view_ui_filter_group.patch, failed testing.

Lendude’s picture

Status: Needs work » Needs review
Issue tags: +JavaScriptTest
FileSize
1.64 KB
2.32 KB

I can't reproduce this locally on OSX with Safari. I get the javascript error but it doesn't interfere with anything. Can anybody reproduce this on other platforms/browsers?

Updated the test so it should pass, and locally for me it passes, so my PhantomJS setup agrees with me. Let's see what the d.o. test bot thinks.

Even if it's not reproducible, the test alone is very much worth it to get this in (javascript tests for Views UI, yay!)

Status: Needs review » Needs work

The last submitted patch, 14: view_ui_filter_group-2717629-14.patch, failed testing.

Lendude’s picture

Status: Needs work » Needs review
FileSize
842 bytes
2.41 KB

Hmm really working for me locally.

Drupal test run
---------------

Tests to be run:
  - Drupal\Tests\views_ui\FunctionalJavascript\FilterCriteriaTest

Test run started:
  Saturday, June 4, 2016 - 23:34

Test summary
------------

Drupal\Tests\views_ui\FunctionalJavascript\FilterCriteriaTes   1 passes                                      

Test run duration: 38 sec

Trying a different waiting strategy, since there is a weird double loading of the dialog.

Status: Needs review » Needs work

The last submitted patch, 16: view_ui_filter_group-2717629-16.patch, failed testing.

Lendude’s picture

Status: Needs work » Needs review
FileSize
1.57 KB
2.27 KB

Did some brainstorming with @dawehner on IRC and maybe the new group is not visible on d.o. because it somehow doesn't fit in the dialog.

So lets give it some more room by using a View with less filters set up. This passes locally too, but lets see what happens here.

Status: Needs review » Needs work

The last submitted patch, 18: view_ui_filter_group-2717629-18.patch, failed testing.

droplet’s picture

The last submitted patch, 3: view_ui_filter_group.patch, failed testing.

Lendude’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
80.96 KB
840 bytes
2.32 KB

You SHOULD start with UNTOUCHED VIEW to test.

I don't understand what you are trying to say.

The test in #3 will always fail because it tries to test isVisible on an element that isn't visible (the Add / Or rearrange button)

One other wait assertion to try.

For illustration, this is a screenshot taken during the test after the 'add group' click and wait.

Trying to figure out a way to do screenshots on d.o.

Status: Needs review » Needs work

The last submitted patch, 22: view_ui_filter_group-2717629-22.patch, failed testing.

The last submitted patch, 22: view_ui_filter_group-2717629-22.patch, failed testing.

pcambra’s picture

pcambra’s picture

I think this is related

pcambra’s picture

Lendude’s picture

Status: Needs work » Needs review
FileSize
2.09 KB

Updated test to use assertWaitOnAjaxRequest(). This still passes locally using both phpunit directly and run-tests.sh

Status: Needs review » Needs work

The last submitted patch, 28: view_ui_filter_group-2717629-28.patch, failed testing.

droplet’s picture

+++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php
@@ -0,0 +1,55 @@
+    $dropbutton->click();
+    $add_link = $page->findById('views-rearrange-filter');

It seems this part doesn't fast enough to response the next click in testbots.

I often hit this error in my own projects. We dropped a timer there ( http://codeception.com/docs/modules/WebDriver#waitForElementVisible )

For behat:
http://docs.behat.org/en/v2.5/cookbook/using_spin_functions.html

(or waitForAjaxToFinish may work, waiting until the CSS changes)

But in #2, I can reproduce bug with human HANDs and mouse :s

Lendude’s picture

Well according to the test result it fails on the last assertion FilterCriteriaTest.php on line 52.

So that is inline with the described bug in the issue summary. But like I said before, I can't reproduce it by hand, nor can I reproduce this test failure on my local setup. So without the ability to reproduce anything, I'm leaving this to others to fix. I just wanted to update the existing patch to use the latest available methods.

matsbla’s picture

Version: 8.1.0 » 8.2.1

I have same problem!
I can confirm the bug is present in Drupal 8.2.1.
It can easily be reproduced by making a fresh install for drupal at simplytestme and following the steps above:
https://simplytest.me/project/drupal

After you clicking "Create new filter group" I have some different behaviors; Sometime the new filter group disappears just after some seconds, another time it did in fact stay there. To me it seems like the group disappears if you move your mouse a lot after clicking "Create new filter group", but remains there if you try keep the mouse still for some time after clicking.

After some hassle I managed to drag 1 field inside the new filter group, however after I click "Apply" and then "Save" it seems like the filter group is not saved after all!

After I managed to drag 2 field inside the new filter group and then it finally worked. When I try to remove one filter group again, these changes are not applied. It seems like the filter group will not be saved if there is only 1 field inside it, I'm not sure if this is related.

droplet’s picture

Version: 8.2.1 » 8.2.x-dev
michielnugter’s picture

Status: Needs work » Needs review
FileSize
421 bytes
2.59 KB

The problem was that the form was submitted twice, this was visible by the dialog disappearing and appearing.

I checked the JavaScript and the problem was with the way the form was submitted in the clickAddGroupButton method. The mousedown event also triggers the submit thus triggering only this event is enough. The submit event was the problem as it triggered the second, invalid (missing the clicked button, causing all kinds of problems), submit.

Please verify this fixes the issue.

michielnugter’s picture

Now without the newline.

Lendude’s picture

Status: Needs review » Needs work

@michielnugter nice!

+++ b/core/modules/views_ui/js/views-admin.js
@@ -736,9 +736,7 @@
       // Due to conflicts between Drupal core's AJAX system and the Views AJAX
       // system, the only way to get this to work seems to be to trigger both
       // the mousedown and submit events.

At the very least we should update this comment. But apparently this was specifically needed at some point.

Looking at #2168893: Views filters groups adding and removing is broken, for the clickRemoveGroupButton function, this double trigger was added because it didn't work without it. And before that fix there was a comment in the clickRemoveGroupButton function:

// For some reason, here we only need to trigger .submit(), unlike for
// Drupal.viewsUi.RearrangeFilterHandler.prototype.clickAddGroupButton()
// where we had to trigger .mousedown() also.

So for some reason the need to trigger two things has switched from add to remove??

michielnugter’s picture

Hmm, missed the comment. Weird that the solution in the mentioned issue was accepte, it's a very dirty solution and actually a workaround for the actual bug.

I dug into it a little deeper.

The add button has a mousedown event handler in:
- (!) misc/ajax.js line 532
- views_ui/js/ajax.js line 43

The remove button misses the misc/ajax.js event handler, which handles the ajaxified submit. As I understand this is caused by either:
- An incorrect way of initializing the submitbutton, causing it not to be recognized by the ajax framework.
- Not passing the new drupal settings to JavaScript after adding the new group.

The trigger for the 'submit' event works around the problem of missing the ajaxified submit by triggering the form submit, which was already ajaxified.

I haven't had the time yet to dig into it deeper to figure out which it is.

michielnugter’s picture

Status: Needs work » Needs review
FileSize
1.39 KB
3.72 KB

It seems it was the first option, the submitbutton was not ajaxified. I made a small change to ajaxify it and and I removed the other 'submit' event trigger. It still works here and the test passes, let's see if it still passes here as well.

I also removed the comment as it's nothing special anymore..

droplet’s picture

+++ b/core/modules/views_ui/js/views-admin.js
@@ -733,9 +733,6 @@
-      // Due to conflicts between Drupal core's AJAX system and the Views AJAX
-      // system, the only way to get this to work seems to be to trigger both
-      // the mousedown and submit events.
       this.addGroupButton.trigger('mousedown');

I always wonder what that is in the beginning. There is few place in CORE used this pattern.

+++ b/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php
@@ -129,6 +129,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
+          '#ajax' => ['url' => NULL],

I didn't dig into source yet. Will it explain why it's random failing (in real human testing & real browser)?

Lendude’s picture

Will it explain why it's random failing

Hmm yeah, good question.

+++ b/core/modules/views_ui/js/views-admin.js
@@ -750,7 +745,7 @@
+      this.table.find('#' + event.data.buttonId).trigger('mousedown');

This will of course need additional testing, but I feel that making both buttons operate the same way is a good addition and within scope here.

michielnugter’s picture

The random failures have a somewhat likely explanation. Currently, the click on the add button triggers 2 AJAX calls to the server (in this order):

  1. A correct one with a triggering element. This respons will add a filter group
  2. An incorrect one without a triggering element. This respons will not change anything in the form.

If the second request finishes last, the form doesn't contain the new filter group.

I reverted the patch to test the behavior and got exactly what I expected. Sometimes it works, sometimes it doesn't. It completely depends on which request finishes last. When applying the patch again the double AJAX load is gone and both the buttons work consistently and without any flickering.

On the other note: I searched core for the incorrect 'submit' event trigger, it's nowhere to be found luckily.

michielnugter’s picture

Now with additional testing for the remove button. I also moved the user creation and variable setting to the setUp() method.

michielnugter’s picture

... And better naming and more comments after lendude's feedback.

michielnugter’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 43: view_ui_filter_group-2717629-43.patch, failed testing.

Lendude’s picture

Status: Needs work » Reviewed & tested by the community

@michielnugter nice clean up.

We have a test, we have a fix, we have a good explanation of the randomness.

  • catch committed b405f34 on 8.3.x
    Issue #2717629 by Lendude, michielnugter, droplet, catapipper, dbyers55...

  • catch committed a19685c on 8.2.x
    Issue #2717629 by Lendude, michielnugter, droplet, catapipper, dbyers55...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Looks great and nice to have a proper js test for it.

Committed/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!

Status: Fixed » Closed (fixed)

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