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
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3555568-7.diff | 1.77 KB | herved |
Issue fork htmx-3555568
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
herved commentedCI failure on 1.6.x looks related to https://git.drupalcode.org/project/htmx/-/commit/71890ab8a300e408ba7a7fd...
Comment #7
herved commentedComment #9
herved commentedI've been running this patch for 6 months without any feedback or movement on the issue, so I've decided to replace the module with a custom controller for our specific use case (lazy-loading a mobile menu block via htmx).
Comment #10
fathershawnI'm been mostly focused on htmx in core these past 6 months. A custom controller is an understandable solution and I will get to this issue for review as soon as can manage it among all the other priorities.
Comment #11
fathershawnFix the bug on 2.x and backport to 1.5 and 1.4
Comment #14
fathershawnComment #19
fathershawnFixed on 2.x and backported to 1.5.x and 1.4.x