Closed 6insanes closed 11 months ago
It can be reproduced with the following test snippet
public function testRedirectWithAcceptHeader(): void
{
$dehydrated = $this->dehydrateComponent($this->mountComponent('with_actions'));
$this->browser()
->throwExceptions()
->get('/_components/with_actions', ['query' => ['props' => json_encode($dehydrated->getProps())]])
->assertSuccessful()
->interceptRedirects()
->use(function (Crawler $crawler, KernelBrowser $browser) {
$rootElement = $crawler->filter('ul')->first();
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
$browser->post('/_components/with_actions/_batch', [
'body' => [
'data' => json_encode([
'props' => $liveProps,
'actions' => [
['name' => 'redirect'],
['name' => 'exception'],
],
]),
],
'headers' => [
'Accept' => ['application/vnd.live-component+html'],
'X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value')
],
]);
})
->assertStatus(204)
->assertHeaderContains('X-Live-Redirect', '1')
;
}
Hey @6insanes! Thanks for the report! I managed to reproduce it locally. Are you up for a PR?
Hi!
This is a bug report. Bug relates to
BatchActionController
andLiveComponentSubscriber::onKernelResponse
.I have simple
LiveComponent
classUserForm
withComponentWithFormTrait
andsubmit
LiveAction
which looks like this:On the web page we have submit button with
data-action="live#action"
anddata-action-name='prevent|submit'
attributes. When changing form data and hitting submit button quickly multiple times I got 500LogicException
from/_components/UserForm/_batch
I think this happens because in
BatchActionController
condition on line 45$response->isRedirection()
is never true and loop continues and action is executed multiple times even ifLiveAction
returns redirection response. Loop continues becauseLiveComponentSubscriber::onKernelResponse
interferes and changes subrequests http response code toResponse::HTTP_NO_CONTENT
which is 204 andResponse::isRedirection
method checks for >= 300 and < 400.Possible solution is to add to
LiveComponentSubscriber::onKernelResponse
check for$event->isMainRequest()
because changing response http code and addingREDIRECT_HEADER
makes sense only for main request.php: 8.1 symfony: 6.3 symfony-ux: 2.13.2