Problem/Motivation
I encountered an issue in Drupal 11.3.7 where an exposed filter is applied twice after page load when navigating using a custom anchor/button link containing a query parameter in array format.
Example Link Used:
<a href="/filter-page?selectedFilters=item[73]" class="button button-primary button-arrow">
Learn More
</a>
When opening the page using the custom link, the View initially loads with the expected filtered result based on the query parameter.
Immediately after the page finishes loading, an automatic AJAX request is triggered by the exposed form.
During that AJAX request, the filter value is processed again and appended as an additional query parameter.
The URL changes from:
/filter-page?selectedFilters=item[73]
to:
/filter-page?selectedFilters=item%5B73%5D&item%5B73%5D=73
Steps to reproduce
1. Create a page with a View exposed filter using AJAX enabled.
2. Add a custom link/button pointing to the filter page with query string: (/filter-page?selectedFilters=item[73])
3. Click the button.
4. Page loads normally.
5. After page load, AJAX runs automatically.
6. Filter gets applied twice.
Actual Result:
The URL changes to:
/filter-page?selectedFilters=item%5B73%5D&item%5B73%5D=73
It appears the filter parameter is duplicated / reprocessed, causing AJAX to apply the filter twice.
Expected Result:
The filter should apply only once, and the URL should remain clean without duplicate parameters.
Comments
Comment #2
kishor kumar v commentedComment #3
quietone commentedHi, Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.
Comment #4
cilefen commentedWhat does it mean for a filter to apply twice? How is this diagnosed technically?
Update the issue summary with this information.
Comment #5
cilefen commentedI am fairly sure the link you constructed is not a normal views link. selectedFilters is written as a single parameter, which means the rest of the query string is taken as a single value.
Comment #6
kishor kumar v commentedBy "filter applies twice," I mean the following behavior:
When opening the page using the custom link, the View initially loads with the expected filtered result based on the query parameter.
Immediately after the page finishes loading, an automatic AJAX request is triggered by the exposed form.
During that AJAX request, the filter value is processed again and appended as an additional query parameter.
The URL changes from:
/filter-page?selectedFilters=item[73]
to:
/filter-page?selectedFilters=item%5B73%5D&item%5B73%5D=73
Comment #7
kishor kumar v commentedComment #8
cilefen commentedselectedFiltersisn't built into Drupal Views. The best way to resolve this issue would be for you to install Drupal and create a view that references existing content types. Then, export the view configuration and attach the YAML to a comment so someone can reproduce the setup.