Route not found error when creating new search pages

Created on 21 April 2025, 23 days ago

Problem/Motivation

When creating a new search page in Drupal's search module (/admin/config/search/pages), users encounter an error immediately after saving the form. This occurs because there's a race condition between saving the search page configuration and rebuilding the routes. The error manifests as "Route 'search.view_[machine_name]' does not exist" and requires a page refresh to resolve.

Steps to reproduce

Go to /admin/config/search/pages
Click "Add search page"
Select any search type (e.g., "Content")
Fill in the form and save
Observe the error: "Route 'search.view_[machine_name]' does not exist"
Refresh the page to see it working correctly

Proposed resolution

Modify the SearchPageAddForm to rebuild routes immediately after saving the search page configuration. This ensures the routes are available in the same request where the search page is created.

Remaining tasks

Add tests to verify the fix
Review and apply patch
Update documentation if necessary

User interface changes

None.

Introduced terminology

None.

API changes

Minor change to SearchPageAddForm to add router.builder service dependency.

Data model changes

None.

Release notes snippet

Fixed a bug where creating new search pages would show a route not found error until the page was refreshed.

๐Ÿ› Bug report
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

search.module

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium baikho Antwerp, BE

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

Merge Requests

Comments & Activities

  • Issue created by @baikho
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium baikho Antwerp, BE
  • Pipeline finished with Failed
    23 days ago
    Total: 718s
    #478692
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium baikho Antwerp, BE
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies โ†’ .

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium baikho Antwerp, BE

    #5 Thanks!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    prashant.c โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    Great find. Was able to replicate easily on 11.x as well and got the following error, while creating any type of search page (node, user and help):

    The website encountered an unexpected error. Try again later.
    
    Symfony\Component\Routing\Exception\RouteNotFoundException: Route "search.view_content" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 214 of core/lib/Drupal/Core/Routing/RouteProvider.php).
    Drupal\Core\Routing\UrlGenerator->getRoute() (Line: 290)
    Drupal\Core\Routing\UrlGenerator->generateFromRoute() (Line: 105)
    Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute() (Line: 773)
    Drupal\Core\Url->toString() (Line: 176)
    Drupal\Core\Utility\LinkGenerator->generate() (Line: 104)
    Drupal\Core\Render\Element\Link::preRenderLink()
    call_user_func_array() (Line: 107)
    Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 848)
    Drupal\Core\Render\Renderer->doCallback() (Line: 393)
    Drupal\Core\Render\Renderer->doRender() (Line: 203)
    Drupal\Core\Render\Renderer->render() (Line: 491)
    Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 184)
    __TwigTemplate_cb3fcbd5c3a204683387ed7f057a01d2->doDisplay() (Line: 388)
    Twig\Template->yield() (Line: 344)
    Twig\Template->display() (Line: 359)
    Twig\Template->render() (Line: 51)
    Twig\TemplateWrapper->render() (Line: 34)
    twig_render_template() (Line: 369)
    Drupal\Core\Theme\ThemeManager->render() (Line: 452)
    Drupal\Core\Render\Renderer->doRender() (Line: 465)
    Drupal\Core\Render\Renderer->doRender() (Line: 465)
    Drupal\Core\Render\Renderer->doRender() (Line: 203)
    Drupal\Core\Render\Renderer->render() (Line: 242)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 599)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 235)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 131)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray() (Line: 246)
    Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}() (Line: 206)
    Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (Line: 56)
    Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (Line: 188)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 715)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
  • Merge request !11911Rebuild route in Search form base โ†’ (Open) created by prashant.c
  • Pipeline finished with Failed
    23 days ago
    Total: 92s
    #479149
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    Needs a review, and then the changes could be backported.

  • Pipeline finished with Success
    23 days ago
    Total: 334s
    #479154
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    prashant.c โ†’ changed the visibility of the branch 10.4.x to hidden.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sdhruvi5142

    Hi,
    Applied and verfied MR!11911 on drupal 11.x version and it is working as expected. Error has been removed.

    Testing Steps:

    1. Install and did set up for drupal 11.x
    2. Go to /admin/config/search/pages
    3. Click "Add search page"
    4, Select any search type (e.g., "Content")
    5. Fill in the form and save
    6. Observe the error: "Route 'search.view_[machine_name]' does not exist"

    Testing Result:
    Before applying patch I was able to see the error (added ss for reference) and after applying the patch following the above steps error isn't being displayed and it is working as expected.
    Added screenshots for reference. So moving this to RTBC+1

    Status: PASS

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    Thanks @sdhruvi5142 for testing the changes, code review also needed for this, changing to NR.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Small comment on MR but probably needs test coverage too.

  • Pipeline finished with Success
    21 days ago
    Total: 527s
    #480907
  • Pipeline finished with Failed
    21 days ago
    Total: 134s
    #480949
  • Pipeline finished with Success
    21 days ago
    Total: 658s
    #480953
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
Production build 0.71.5 2024