The context of main content block does not include 'url' or 'route'

Created on 24 June 2016, over 8 years ago
Updated 20 May 2024, 6 months ago

In RefreshLessPageState.php:

  /**
   * Check whether a region (or block or …) has changed from the previous page.
   *
   * @param \Drupal\Core\Cache\CacheableMetadata $cacheability
   *   The cacheability of a region (or block or …), to check whether it would
   *   have changed compared to the previous page.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request, to check whether
   *
   * @return bool
   *   Whether this region (or block or …) has changed.
   */
  public function hasChanged(CacheableMetadata $cacheability, Request $request) {
    $current_context_hashes = $this->getSensitiveContextHashes($cacheability->getCacheContexts());
    $previous_context_hashes = $this->read($request)['cache_contexts'];

    return $current_context_hashes != array_intersect_key($previous_context_hashes, $current_context_hashes);
  }

I assume that the detection of change is based on cache context. However, I just found out that main content block for a node page actually does not include 'route' or 'url'. That is to say, the main content block of 'node/1', 'node/2', 'node/3' all have the same cache context.

I discovered this when working on the cache context of blocks. At region level, this issue might not appear because some other blocks in the Content region contains route cache context, and is 'bubbled up'. However, if I remove all blocks except main content block in the Content region, RefreshLess cannot detect change in Content region correctly.

The cache context of main content block on the front page is indeed different from those on node/* pages. But stranglely, RefreshLess only works when navigating from node/* pages to the frontpage, and not the reverse.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

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.

No activities found.

Production build 0.71.5 2024