Avoid preloading routes in subrequests

Created on 1 June 2025, 4 days ago

Problem/Motivation

On a 404, we make a subrequest to the configured 404 page.

Because route preloading happens in a request subscriber it runs twice.

Steps to reproduce

Proposed resolution

Add an ::isMainRequest() check to route preloading so it only ever runs once.

Alternatively see if we can move it somewhere on-demand in the routing system, just before we try to lookup a route.

This is potentially testable with a performance test - we should see one less cache get on a 404 (without page_cache running or on a miss).

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component

routing system

Created by

🇬🇧United Kingdom catch

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

Comments & Activities

  • Issue created by @catch
  • 🇬🇧United Kingdom catch

    Exactly the same thing happens with the cache tag preload subscriber, this might be small enough to do both in one issue.

  • 🇬🇧United Kingdom catch
  • 🇬🇧United Kingdom catch

    Nope cache tags properly checks isMainRequest() already.

  • 🇬🇧United Kingdom catch

    Also this is wrong in general.

    RouteProvider::preloadRoutes() is getting called twice - once with <current> and once with system.404, both load the route from cache because the RoutePreloader::onRequest() never gets called.~

    One lookup is for the front page cache context, and the other is for redirect destination. So I was seeing something different to what is actually happening. There might be a saving here, but it's not an issue of the preload routes being loaded twice.

Production build 0.71.5 2024