Potential caching issue when modifying the mobile menu with hooks

Created on 23 October 2019, about 5 years ago
Updated 21 November 2023, about 1 year ago

From issue #2958328: Multiple menu blocks for multiple sites (domain access) โ†’

I tried to change the menu used for mobile applying the described hook on #2 but there are some cache issues. First time an user enters a specific page, it shows the correct menu but that remains the same for other parts of the site when the menu needs to change to another one. I tried to disable all site cache and even disabling specific block's cache in a custom module

This needs some investigating and checking to make sure that caching is appropriately applied.

๐Ÿ› Bug report
Status

Needs review

Version

4.4

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡นItaly tanc Italy

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.

  • ๐Ÿ‡ต๐Ÿ‡นPortugal introfini

    In my case adding the cache context to $build had no effect.

    I had to it in the $rendered_tree["#cache"]["contexts"][] = 'user';

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Raveen Kumar

    Raveen Thakur โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly tanc Italy

    If you add the user cache context then the rendered_tree cache will vary per user which might not be what you want. It pretty much makes the page uncacheable for logged in users.

  • ๐Ÿ‡ต๐Ÿ‡นPortugal introfini

    Unfortunately, that's really what I need, at least until the horrible idea of adding a block to the menu tree that varies by user is refactored.

    Thanks for the alert!

  • ๐Ÿ‡ช๐Ÿ‡ธSpain uridrupal

    Once I added patch #14 it was also necessary to add:

    /**
     * Implements hook_responsive_menu_off_canvas_tree_prebuild().
     */
    function mymodule_responsive_menu_off_canvas_tree_prebuild(array &$build) {
      $build['#cache']['contexts'][] = 'subsite_context';
    }

    After doing this, I had no more issues with cache.

Production build 0.71.5 2024