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

CommentFileSizeAuthor
#7 3555568-7.diff1.77 KBherved

Issue fork htmx-3555568

Command icon 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

herved created an issue. See original summary.

herved’s picture

herved’s picture

Status: Active » Needs review
StatusFileSize
new1.77 KB

herved changed the visibility of the branch 3555568-htmx-blocks-fail to hidden.

herved’s picture

I'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).

fathershawn’s picture

I'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.

fathershawn’s picture

Version: 1.6.x-dev » 2.x-dev

Fix the bug on 2.x and backport to 1.5 and 1.4

fathershawn changed the visibility of the branch 2.x to hidden.

fathershawn’s picture

Status: Needs review » Needs work

  • fathershawn committed 23d686a1 on 1.5.x authored by herved
    fix: #3555568 HTMX blocks fail to render on 404 error pages
    
    By: herved...

  • fathershawn committed e030fa3d on 2.x
    fix: #3555568 HTMX blocks fail to render on 404 error pages
    
    By: herved...

  • fathershawn committed 6b38b71b on 1.4.x
    fix: #3555568 HTMX blocks fail to render on 404 error pages
    
    By: herved...
fathershawn’s picture

Status: Needs work » Fixed

Fixed on 2.x and backported to 1.5.x and 1.4.x

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.