Move custom active trail detection to client-side JavaScript - #831
Conversation
Remove the server-side active trail workaround that added url.path cache context to every menu render, causing the menu block to be cached per URL path. Replace with a lightweight client-side JavaScript that detects the active trail by comparing menu link hrefs against the current URL pathname. Core's built-in in_active_trail continues to work for standard menu links; the JS covers edge cases like Views-generated menu links (core issue #3359511). Fixes #827
|
Review findings:
Checks: I tried to submit this as a formal request-changes review, but GitHub does not allow the PR author account to request changes on its own PR. |
Skip external links in client-side active trail detection by checking origin before comparing pathnames. Fix @deprecated version to 8.2.0 since the theme is already past 8.x. Clarify scope: this PR removes the url.path cache context, not the core active trail cache context.
|
Follow-up after
|
Links with href="#" resolve to the current page URL, causing them to be falsely marked active on every page. Check the raw href attribute and skip fragment-only values before pathname comparison.
Linked issues
Solution
Remove the custom server-side active trail workaround that added
url.pathcache context to every menu render (causing the menu to be cached per-URL-path). Replace with a lightweight client-side JavaScript that detects the active trail by comparing menu link hrefs against the current URL. Core's built-inin_active_trailcontinues to work for standard menu links; the JS covers edge cases like Views-generated menu links (core issue #3359511).This removes the extra
url.pathcache variation that dxpr_theme was adding. Core'sroute.menu_active_trails:maincache context remains on menu blocks, so the menu still varies by active trail (not by every URL path). This significantly reduces the number of cached menu renders: from one per URL to roughly one per distinct active trail.Checklist