Attach AJAX requests to the existing debug bar - #44
Merged
Conversation
Every AJAX response repeated renderHead() and the initialization code, so the browser built another debug bar on top of the one the main request had already created, instead of adding the AJAX request as a dataset to it. Requests carrying X-Requested-With: XMLHttpRequest now render only render(false), which php-debugbar shows as an "(ajax)" dataset of the existing bar. Force enable/disable and the non-HTML response path keep their current behaviour: a forced disable still wins for AJAX requests, and the wrapper page built for non-HTML responses is a standalone document, so it keeps its head and initialization code. Fixes #41. Takes the approach proposed by @mostafasy in #40, without the exact version constraint on maximebf/debugbar and without attaching the bar to responses that asked for it to be disabled. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Mezzio's ApplicationFactory resolves MiddlewareFactoryInterface and RequestHandlerRunnerInterface, while the test container only knew the concrete classes, so the whole MezzioTest failed on current Mezzio versions with ServiceNotFoundException. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Releases before 1.18.0 miss #[\ReturnTypeWillChange] on DebugBar's ArrayAccess methods and fatal on load under PHP 8.1+, which the package claims to support. 1.16.5 and 1.17.0 were verified to fail as well, so 1.18 is the lowest usable bound; the whole 1.x line stays allowed. Since 1.18 the DataFormatter runs through symfony/var-dumper's VarCloner, whose oldest allowed release (2.6) breaks on PHP 8.0. A require-dev floor keeps the lowest-dependency jobs resolving to a version that runs there; it does not constrain consumers of this package. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
snapshotpl
force-pushed
the
fix/ajax-debugbar-initialization
branch
from
August 19, 2026 16:03
887d01a to
4c5f9d1
Compare
Run on pull requests, cover PHP 8.2 and 8.3, and stop using the retired actions/checkout@v2 and ramsey/composer-install@v1. PHP 7.3 and 7.4 leave the matrix. Composer 2.10, which setup-php installs today, only accepts laminas-diactoros 2.18.1 and newer as a provider of psr/http-factory-implementation, and those releases require PHP 8.0+, so the dev dependencies cannot be installed on 7.3/7.4 at all - with or without the changes in this branch. PHPStan moves to PHP 8.0 for the same reason. The lowest-dependency jobs stay on PHP 8.0: Slim 3.0, Pimple 3.0 and vfsStream 1.6.8 predate PHP 8.1 and fatal on load there, and raising those dev bounds is not an option either, because the first Slim 3 release that supports PHP 8.1 (3.13.0) requires PHP 8.1. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
snapshotpl
force-pushed
the
fix/ajax-debugbar-initialization
branch
from
August 19, 2026 16:04
4c5f9d1 to
3199d5a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #41, supersedes #40 (thanks @mostafasy for the report and the original patch).
The bug
Every AJAX response repeated
renderHead()and the initialization code, so the browser built a second debug bar on top of the one the main request had already created — the stacking @tyrsson described in #41 — instead of adding the AJAX request as a dataset of the existing bar.Requests carrying
X-Requested-With: XMLHttpRequestnow render onlyrender(false), which php-debugbar displays as an(ajax)dataset.Two things differ from #40:
maximebf/debugbaris not pinned to an exact version (see below).shouldReturnResponse()keeps deciding on its own. AJAX request should not render the initialization code. #40 changed it toshouldReturnResponse(...) && ! $isAjax, which would attach the bar to AJAX responses even whenX-Enable-Debug-Bar: falsewas sent. A test covers this case now.The wrapper page built for non-HTML responses keeps its head and initialization code — it is a standalone document, not a fragment inserted into an already initialized page.
Dependencies
maximebf/debugbarminimum goes from^1.4to^1.18. Releases before 1.18.0 miss#[\ReturnTypeWillChange]onDebugBar'sArrayAccessmethods and fatal on load under PHP 8.1+, which this package claims to support (1.16.5 and 1.17.0 were verified to fail as well). The whole 1.x line stays allowed — no exact version.Since 1.18 the
DataFormattergoes throughsymfony/var-dumper'sVarCloner, and its oldest allowed release (2.6) breaks on PHP 8.0, so there is now arequire-devfloor for it. It only affects our lowest-dependency CI jobs, not consumers.CI
The test container did not register
MiddlewareFactoryInterface/RequestHandlerRunnerInterface, soMezzioTestfailed against current Mezzio withServiceNotFoundException.The workflow now runs on pull requests, covers PHP 8.2 and 8.3, and drops the retired
actions/checkout@v2/ramsey/composer-install@v1.PHP 7.3 and 7.4 leave the matrix. This is not caused by anything in this branch — the same failure reproduces on
master. Composer 2.10, whichsetup-phpinstalls today, only acceptslaminas-diactoros2.18.1+ as a provider ofpsr/http-factory-implementation, and those releases require PHP 8.0+:So the dev dependencies can no longer be installed on 7.3/7.4 with a current Composer (an explicit
laminas/laminas-diactoros: ^2.14dev constraint does not help either). PHPStan moves to PHP 8.0 for the same reason. Whether"php": "^7.3 || ^8.0"incomposer.jsonshould follow is a separate support-policy decision and is left untouched here.The
lowestjobs run on PHP 8.0 only: Slim 3.0, Pimple 3.0 and vfsStream 1.6.8 predate PHP 8.1 and fatal on load there, and raising those dev bounds is not an option either, because the first Slim 3 release supporting PHP 8.1 (3.13.0) requires PHP 8.1.Verification
Ran locally in Docker with Composer 2.10:
higheston PHP 8.0, 8.1, 8.2, 8.3 andloweston 8.0 — 30 tests each, plus PHPStan level 6 onsrc/. The new AJAX behaviour is covered by unit tests and by a case inAbstractMiddlewareRunnerTest, so it is asserted against both Mezzio and Slim 3.🤖 Generated with Claude Code