Menu cache is not cleared when adding first item

Created on 15 March 2024, 3 months ago
Updated 1 May 2024, about 2 months ago

Problem/Motivation

If you render a menu using Twig Tweak e.g. drupal_menu('main') and then insert the first item into this menu then this item will not appear immediately. If you clear the cache it will. Modifying menu items in the menu subsequently take effect immediately without needing to clear the cache.

This seems to be a result of the cache keys that Twig Tweak adds to render arrays for menus by default if the Menu Link Tree from Drupal Core has not provided any. I cannot tell from the origin commit why this is needed.

Steps to reproduce

- Render a menu without any items in it using drupal_menu() from Twig Tweak in a template
- Render the template with the menu. No items will be shown
- Add an item to the menu
- Render the template again. No items will be shown.
- Clear the cache
- Render the template again. The item added will be shown.
- Add another item to the menu
- Render the template again. Both items will be shown
- Delete both items
- Render the template again. No items will be shown
- Add a new item to the menu.
- Render the template again. No items will be shown

Proposed resolution

Add a menu_link_content_list:[menu-name] cache key to the list of default cache keys. This will be purged by default by Drupal Core for any changes to the menu links in the menu - including adding the first one.

After the first menu item has been added then the Drupal Core Menu Link Tree will add cache keys on its own ensuring that caches are purged as expected.

Remaining tasks

N/A

User interface changes

N/A

API changes

NA/

Data model changes

N/A

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡©πŸ‡°Denmark kasperg

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024