Views relying on contextual filter defaults always get the url cache context

Created on 6 November 2019, about 5 years ago
Updated 22 December 2023, 11 months ago

Problem/Motivation

Steps to reproduce:

1. Create a view using a user contextual filter. Set the user contextual filter up to fall back to the current user.

2. Check the exported views YAML and see it has the route cache context.

This is because ArgumentPluginBase always adds the url cache context.

 /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    $contexts = [];
    // By definition arguments depends on the URL.
    // @todo Once contexts are properly injected into block views we could pull
    //   the information from there.
    $contexts[] = 'url';

    // Asks all subplugins (argument defaults, argument validator and styles).
    if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) {
      $contexts = Cache::mergeContexts($contexts, $plugin->getCacheContexts());
    }

Proposed resolution

No idea, but if we had a way to specify that the argument is always going to come from the request and never from the URL it might be possible to skip this. Maybe a dedicated User-from-request argument implementing a different interface or something and this overrides that method to not add the URL cache context.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 1 hour ago

Created by

πŸ‡¬πŸ‡§United Kingdom catch

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