Problem/Motivation
I think the approach that the views AJAX system takes to determine views arguments is incorrect. Right now when doing AJAX pagination, the view attempts to get all of the contextual view information from the pager link. If ?page=1 is set on the link, it will use that in it's ajax request. If /VIEW-PATH/arg1/arg2/arg3 is set, it will use those three arguments when executing the view.
This makes sense for query strings because they are never aliased and are required to store the pagination state. The problem with arguments is that all of the argument plugins that load context are aware of the underlying route. For example, when a views block is attached to /user/1 (aliased to /member/admin), the plugins can successfully determine that the view needs to be filtered by user id 1.
When an AJAX pagination link is clicked, the arguments are attempted to be determined from the HREF of the link. This is done on the client and has no knowledge of being able to pull an argument value from a route. The result is /member/admin is parsed and "admin" is determined as the argument for the view. Once this filters through to executing the view, the context of this being an entity ID that can be filtered with is lost and the view returns 0 results.
I don't believe we can successfully parse a views arguments on the client without the routing context.
Proposed resolution
When paginating, don't recalculate the views arguments based on the link HREF. Use the same arguments that were present when the view loads.
I believe this makes sense because it's unlikely you would ever want arguments to change between pages.
Remaining tasks
Validate/patch/test.
User interface changes
TBD.
API changes
TBD.
Data model changes
TBD.
Comment | File | Size | Author |
---|---|---|---|
#55 | 2703771-55.patch | 609 bytes | sahil.goyal |
#50 | interdiff-2703771-49_50.txt | 631 bytes | Gauravvvv |
#50 | 2703771-50.patch | 1.2 KB | Gauravvvv |
#49 | drupal-n2703771-49.patch | 1.23 KB | DamienMcKenna |
Comments
Comment #2
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThis fix is working for my project.
Comment #3
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #4
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #6
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedRelative to core (for my own testing). Please ignore.
Comment #8
jibranHave you tested this with expose filters?
Comment #9
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAs far as I can see, the patch only touches pager links. Haven't manually tested with exposed filters.
Comment #10
dawehnerComment #11
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commented#2 applies, #6 was for my use relative to core so I could apply the patch with composer.
Comment #12
dawehnerLet's ensure to add tests for that. I would also avoid removing that API to be honest, you know, maybe someone is actually using it.
Comment #13
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedIt looks like it only used in the context of pagination, no generic kind of view-ajax-link-api, so I'm not sure how changing a views argument would be applicable to that at all, ever.
This is likely to be a huge test with perhaps limited benefit? We're essentially removing a feature and want to asset that it's gone?
Comment #14
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedBy the way I looked up the history of the code and it looks like it's left over untouched from the 7.x days. I think it's just an oversight that can be corrected by deleting the "feature".
Comment #15
dawehnerI'm actually more talking about the bug you described here:
Sure I'll RTBC this patch and then a committer will push it back. Believe me, just keep the function around will just make all our life easier :)
Comment #16
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedYou mean leave the function there but don't use it anywhere in Drupal?
Comment #17
dawehnerYeah ...
Comment #18
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedOkay, that makes sense. Thanks for the clarification.
Comment #19
Saphyel CreditAttribution: Saphyel as a volunteer commentedI tried on my local without your patch and AJAX pagination works fine on 8.2.x. Could you provide details for replicate this ?
Comment #20
dawehner@Saphyel Did you also tried path aliases?
Comment #21
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedYep, you need a view on a path which is aliased, eg user/1 to member/username, then select one of the contextual filter plugins which grabs an entity ID from the matched route.
Comment #22
Saphyel CreditAttribution: Saphyel as a volunteer commentedyep you are right guys, also doesn't work the patch I noticed that for some reason in the 2nd page load changes the "view_path" to "/views/ajax", and lose another elements like "page:1" etc...
Comment #24
jesse.voogt CreditAttribution: jesse.voogt at Plethora commentedI'm experiencing the same symptoms (based on inspecting the Net panel when clicking "show more"), but for Drupal 7. Any chance of making a version of the patch for D7 as well?
Comment #25
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commented7.x-3.x version in the views queue. #2805539: Views argument set incorrectly when using AJAX pagination and a path alias
Comment #27
sluceroBased on the issues mentioned here with
view_path
being changed, I expect this issue may be solving the same problem from a different approach as #2866386: Assert the view path is set correctly after second ajax request.Comment #29
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedReroll.
Comment #32
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedReroll.
Comment #34
chiranjeeb2410 CreditAttribution: chiranjeeb2410 at Google Summer of Code commentedRerolled against latest core from #18
Comment #36
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedNow I am getting a syntax error in Firefox and Chrome
Chrome:
Uncaught SyntaxError: Unexpected token .
Firefox:
SyntaxError: missing : after property id[Learn More]
Firefox gives an explanation:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors...
When creating objects with the object initializer syntax, a colon (:) separates keys and values for the object's properties.
Comment #38
mbovan CreditAttribution: mbovan at MD Systems GmbH commented#22, #27
view_path
was fixed in #2820347: Exposed filter reset redirects user to 404 page on AJAX view when placed as a block.@Sam152, do we still need #34 patch for path aliases or can we close this issue as a duplicate?
Comment #40
andypostBoth path aliases and pager changed in 8.8 core
Comment #42
loopy1492 CreditAttribution: loopy1492 commentedWorse, the code in #34 seems to be incompatible with some versions of jquery. I'm getting
Uncaught SyntaxError: Unexpected token '.'
on the added line and my text editor is upset about the new nesting.
Comment #44
Ericmaster CreditAttribution: Ericmaster as a volunteer commentedHaven't tested yet but the following patch should fix the Unexpected token issue.
Comment #45
Ericmaster CreditAttribution: Ericmaster as a volunteer commentedThe following patch worked for me against 8.9.x
Comment #47
ChristianSanders CreditAttribution: ChristianSanders at ComputerMinds commentedAmended a working patch for use on 9.1.x.
Comment #48
DamienMcKennaRerolled. Note that the JS has changed notably since the original patch was written, I recommend reviewing the logic to confirm whether it follows the latest JS standards or could be improved.
Comment #49
DamienMcKennaRerolled.
Comment #50
Gauravvvv CreditAttribution: Gauravvvv at OpenSense Labs for Drupal India Association commentedFixed CS errors, Attached interdiff for same. Please review.
Comment #55
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedreroll patch for 10.1.x