Views exposed form block options are not updated immediately when adding additional sorts, filters, etc (Caching?)

Created on 18 June 2017, over 7 years ago
Updated 17 May 2023, over 1 year ago

Problem/Motivation

In the process of triaging issue 🐛 Table clicksort is lost when using views exposed filter Needs work @xjm and I encountered another problem relating to the views exposed block form where the options and/or widgets displayed on the exposed block were not immediately visible on the view page after changing the configuration of the view itself.

Steps to reproduce

  1. Add some content into a default new standard profile 8.4.x HEAD D8 site
  2. Create a page view (with URL /sortmissing), add exposed filters for sorting criteria (eg. content type for filter and authored on, authored by, for sort criteria)
  3. Add a full pager with exposed option "Allow user to control the number of items displayed in this view"
  4. Under Advanced config of the view, select Yes for Exposed Form, choosing Basic form type
  5. Under Structure - Block Layout - Place Block choose the newly created exposed form and place it in a region (eg. Sidebar)
  6. Go the view page (/sortmissing), notice which options and widgets are shown
  7. Change the view and add another option into an existing filter (eg. add Title to the Sort Criteria so that you have three options: authored on, authored by and title as options there)
  8. Switch back to view page and just refresh the page or click Apply on the exposed block form to refresh the display - the resulting page does not show the newly added option

Based on how unpredictable the display of the exposed block options happens as it eventually refreshes after a few attempts clicking on the page and the various options (usually after 3-4 refreshes of changing the chosen filtering options things seem to update), this would possibly be related to caching and how the cache is being invalidated on the exposed filters block for the view.

Attached with the issue is the export of the view I've used to arrive at the issue.

- - - - - - - - - - - - - -

This issue emerged from 🐛 Table clicksort is lost when using views exposed filter Needs work and the following folks deserve credit:
@anneeasterling = #2823541-9: Table clicksort is lost when using views exposed filter
@krknth = #2823541-10: Table clicksort is lost when using views exposed filter

Proposed resolution

Override getCacheTags method and pass relevant cache tags.

  public function getCacheTags(): array {
    $tags = parent::getCacheTags();
    // Add the tag for the View this block belongs to.
    return Cache::mergeTags($tags, ['config:views.view.' . $this->view->id()]);
  }

Remaining tasks

Needs review

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Needs work

Version

10.1

Component
Views 

Last updated about 8 hours ago

Created by

🇨🇦Canada samirjusic

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024