Active
Project:
Drupal core
Version:
main
Component:
ajax system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 Jan 2026 at 08:12 UTC
Updated:
28 Jan 2026 at 07:13 UTC
Jump to comment: Most recent
Looks like htmx:beforeRequest is never triggered, and requestAssetsLoaded isn't populated, causing htmx:beforeSwap to fail with Uncaught TypeError: can't access property "then", requestAssetsLoaded.get(...) is undefined.
Add the following controller:
# htmx_example.routing.yml
htmx_example.htmx_response:
path: '/htmx-example/htmx'
defaults:
_controller: '\Drupal\htmx_example\Controller\HtmxExampleController::htmx'
options:
_htmx_route: 'TRUE'
requirements:
_permission: 'access content'
# src/Controller/HtmlExampleController.php
declare(strict_types=1);
namespace Drupal\htmx_example\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Htmx\Htmx;
use Drupal\Core\Url;
final class HtmxExampleController extends ControllerBase {
public function htmx(): array {
return [
'#type' => 'markup',
'#markup' => 'Some content',
];
}
}
and a render array like:
$htmx = new Htmx();
$htmx->get(new Url('htmx_example.htmx_response'))
->trigger('load');
$build = [
'#type' => 'html_tag',
'#tag' => 'div',
];
$htmx->applyTo($build);
Comments
Comment #2
tuutti commentedActually, this seems to have nothing to do with GET vs. POST requests. The original code appeared to work after switching to POST, but that didn't actually fix the issue.