[12.x] Prevent unnecessary query logging on exceptions with a custom renderer #56874
+104
−1
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.
Reopen: #56865
The Problem
When a package like
spatie/laravel-ignition
is installed, it provides its ownExceptionRenderer
. However, the framework's default exception listener is still registered alongside it. This causes every exception to be handled twice, resulting in redundant work and unnecessary memory usage (e.g., populating$queries
when it is not needed).Simple Recreation
spatie/laravel-ignition
in a fresh Laravel project.dd()
to the framework's default listener to see it run:/test-exception
in the browser. You will see thedd()
message, proving the default listener ran when it shouldn't have.The Solution
This PR adds a check (
! $this->app->bound(ExceptionRenderer::class)
) to ensure the default listener is only registered if no otherExceptionRenderer
has already been bound to the container. This cleanly prevents the duplication.Tests
ExceptionRenderer
exists.ExceptionRenderer
does not exist.