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):
- A correct one with a triggering element. This respons will add a filter group
- 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
-
Comment | File | Size | Author |
---|---|---|---|
#43 | view_ui_filter_group-2717629-43.patch | 4.24 KB | michielnugter |
#43 | interdiff-42-43.txt | 2 KB | michielnugter |
#42 | view_ui_filter_group-2717629-42.patch | 4 KB | michielnugter |
#42 | interdiff-38-42.txt | 1.53 KB | michielnugter |
#38 | view_ui_filter_group-2717629-38.patch | 3.72 KB | michielnugter |
Comments
Comment #2
droplet CreditAttribution: droplet commentedConfirmed. Moved to View thread to see if any duplicated reports.
Comment #3
droplet CreditAttribution: droplet commentedAdd a test
Comment #4
droplet CreditAttribution: droplet commentedTrigger testbot run
Comment #6
catapipperComment #7
catapipperTriaging at DrupalCon New Orleans 2016
Comment #8
catapipperTriaged 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.
Comment #9
dbyers55 CreditAttribution: dbyers55 commentedComment #10
xjmThanks @catapipper and @dbyers55 for helping triage this issue! (Updating issue credit to include triagers.)
Comment #11
vprocessor CreditAttribution: vprocessor at Skilld commentedComment #14
LendudeI 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!)
Comment #16
LendudeHmm really working for me locally.
Trying a different waiting strategy, since there is a weird double loading of the dialog.
Comment #18
LendudeDid 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.
Comment #20
droplet CreditAttribution: droplet commentedYou SHOULD start with UNTOUCHED VIEW to test. Comment #1 ~ #3 still validated.
Wrong returns from backend it seems:
https://jsonblob.com/57569226e4b01190df73cc84
It may be related:
#2647916: Views ajax modals stop working in certain scenarios: due to JS settings caching, AJAX responses may set wrong ajaxPageState.libraries, causing problems for subsequent AJAX requests/responses
Comment #22
LendudeI 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.
Comment #25
pcambraComment #26
pcambraI think this is related
Comment #27
pcambraAdding more possible related issues
Comment #28
LendudeUpdated test to use assertWaitOnAjaxRequest(). This still passes locally using both phpunit directly and run-tests.sh
Comment #30
droplet CreditAttribution: droplet commentedIt 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
Comment #31
LendudeWell 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.
Comment #32
matsbla CreditAttribution: matsbla commentedI 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.
Comment #33
droplet CreditAttribution: droplet commentedComment #34
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedThe 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.
Comment #35
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedNow without the newline.
Comment #36
Lendude@michielnugter nice!
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:
So for some reason the need to trigger two things has switched from add to remove??
Comment #37
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedHmm, 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.
Comment #38
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedIt 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..
Comment #39
droplet CreditAttribution: droplet commentedI always wonder what that is in the beginning. There is few place in CORE used this pattern.
I didn't dig into source yet. Will it explain why it's random failing (in real human testing & real browser)?
Comment #40
LendudeHmm yeah, good question.
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.
Comment #41
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedThe random failures have a somewhat likely explanation. Currently, the click on the add button triggers 2 AJAX calls to the server (in this order):
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.
Comment #42
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedNow with additional testing for the remove button. I also moved the user creation and variable setting to the setUp() method.
Comment #43
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commented... And better naming and more comments after lendude's feedback.
Comment #44
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedComment #46
Lendude@michielnugter nice clean up.
We have a test, we have a fix, we have a good explanation of the randomness.
Comment #49
catchLooks 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!