Views pages are not available after being created in a recipe until the cache is cleared

Created on 26 September 2024, 4 months ago

Problem/Motivation

If a recipe provides a view configuration that includes a page display, it is not available until the cache is cleared. This can be observed if trying to access the page directly, but also any related menu item is also not visible until the cache is cleared.

Steps to reproduce

  • Start with a fresh install of Drupal (I completed all the following with Drupal 11)
  • Apply a recipe that includes a view configuration that provides a page display, ideally with a menu item for the page. The Locations recipe β†’ is an ideal example, for a reason that will be made clear later
  • Note that the recipe is applied successfully
  • Go back to the site and observe that the menu item is not visible as expected
  • Attempt to access the view at the expected page path (e.g. /locations) and observe that a 404 is returned
  • Go into the Views listing and see that the Locations Map view has been created
  • Resave the view or clear the cache, and observe that the menu item is now visible, and the page can be accessed as expected.

The locations recipe is ideal for testing, because the same configuration is available in a module, using the 1.0.x branch, which allows us to rule out a problem with the view configuration. To observe this follow the same steps as above, but install the module instead of applying the recipe, and note that the menu item is immediately visible and the page is also accessible, without any additional steps.

Proposed resolution

Ensure that when a recipe creates a views page, it is available right away, and its menu item visible.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

recipe system

Created by

πŸ‡¨πŸ‡¦Canada mandclu

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

Comments & Activities

  • Issue created by @mandclu
  • I will start looking into this issue in the mentored contribution room.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    This feels like the router is not building rebuilt. When a view is saved the router needs rebuild flag should be set - see \Drupal\views\Entity\View::postSave() - so the question is why has this not happened. This feels like the way the recipe commands are being run are not correctly triggering destructable services during kernel termination.

  • I was able to reproduce the issue as mentioned.

    The easiest solution would be to add a cache clear at the end of the RecipeCommand. The question is if this is a sufficient solution. This might lead to unnecessary cache clears, e.g. when applying a recipe that would not require a cache clear or when adding multiple recipes at once.
    The getting started documentation of distributions_recipes, also mentions that a cache clear is required after applying a recipe.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @grietdk we should not need to add a cache clear. The system should do the necessary rebuilding without having to do a generic cache clear.

  • πŸ‡¦πŸ‡ΊAustralia pameeela

    From what I can tell, this only occurs when applying a recipe from command line. I don't think I've seen it when using PB, and just now I tried both (once each, but still) and only had the issue with cli.

    Adding it as a target because the bug is causing a fatal error with the Blog recipe because it includes an RSS feed link in the view. If you install without blog, and apply the recipe from cli, clicking the 'Blog' link in the menu results in:

    The website encountered an unexpected error. Try again later.
    
    Symfony\Component\Routing\Exception\RouteNotFoundException: Route "view.blog.rss" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 211 of core/lib/Drupal/Core/Routing/RouteProvider.php).

    I don't think this is a blocker necessarily, if it's true that it only happens when using cli.

Production build 0.71.5 2024