HTMX blocks fail to render on 404 error pages

Created on 1 November 2025, 2 days ago

Problem/Motivation

\Drupal\htmx\Render\HtmxBlockView::build attempts to "Add the simulated request to the top of the stack". This works well on all pages unless we are on a 404 page because \Drupal\Core\Routing\Router::matchRequest throws a ResourceNotFoundException which will fail to load the block.

Context/use case: I'm using HTMX to load the mobile menu block when clicking on the hamburger icon. This works on all pages except a 404 page, where the xhr request to load the block returns 500 Internal Server Error.
PS: This does not seem to be an issue on 403 pages.

Steps to reproduce

- Go on any 404 page
- Attempt to load an HTMX block
- We get a "500 Internal Server Error" response when HTMX attempts to load the block from /htmx/blocks/view/{block}

Proposed resolution

Add a try/catch on ResourceNotFoundException in HtmxBlockView::build

Remaining tasks

?

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Active

Version

1.6

Component

Drupal Code

Created by

🇧🇪Belgium herved

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024