[12.x] Restore original dispatcher bindings after precognitive request #58716
+49
−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.
Problem
In long-lived processes such as Laravel Octane or Pest Browser's Amp-based HTTP server, a precognitive request permanently pollutes the container. Subsequent non-precognitive requests resolve
PrecognitionCallableDispatcherinstead of the originalCallableDispatcher, causing the controller to be skipped and a 204 response to be returned.Cause
HandlePrecognitiveRequests::prepareForPrecognition()overrides theCallableDispatcherContractandControllerDispatcherContractbindings with precognition variants usingbind(), but never restores the originalsingleton()bindings.In PHP-FPM this is harmless because the process dies after each request, but in long-lived processes the polluted bindings persist across requests.
Solution
Capture the original bindings before overriding them in
prepareForPrecognition(), then restore them in the tap callback after the precognitive response is prepared.Fixes pestphp/pest#1579