Skip to content

Conversation

@datamweb
Copy link
Contributor

@datamweb datamweb commented Dec 20, 2025

Description
The Debug Toolbar injects HTML and JavaScript into every HTML response by default, which works for full page loads but causes issues for client-managed or partial requests (such as those from HTMX, Unpoly, or Hotwire Turbo) that expect clean HTML fragments. This can result in invalid HTML, duplicated scripts, or JavaScript errors like “Maximum call stack size exceeded.” To address this, support was added to skip Debug Toolbar HTML/JS injection for requests containing specific headers (e.g. HX-Request, HX-Boosted, X-Unpoly-Request, Turbo-Frame, Turbo-Visit), while still preserving Debugbar response headers for network-level debugging.

Screenshot 2025-12-20 215637

I don’t consider this PR a new feature. I believe it could have been to the develop branch, but since it introduces the $disableOnHeaders property, I only PR’d it to the 4.7 branch.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Comment on lines +395 to +402
try {
$stats = $app->getPerformanceStats();
if (! isset($stats['startTime']) || ! isset($stats['totalTime'])) {
return;
}
} catch (Throwable) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on why we need a try/catch block here?

}

$toolbar = service('toolbar', $config);
$stats = $app->getPerformanceStats();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling this again?

*/
public array $disableOnHeaders = [
'HX-Request', // HTMX partial requests
'HX-Boosted', // HTMX boosted navigation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't set HX-Boosted without having HX-Request, so the HX-Boosted is not needed.

@michalsn michalsn added enhancement PRs that improve existing functionalities 4.7 labels Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.7 enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants