Skip to content

Commit d288690

Browse files
committed
bug #1301 [Live] Fix BatchActionController redirection (6insanes)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Live] Fix BatchActionController redirection | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | Fix #1300 | License | MIT This should fix #1300 LiveConponentSubscriber::onKernelResponse should not change response status for subrequests I'm not sure about test naming Commits ------- 4f75d06 [Live] Fix BatchActionController redirection
2 parents f60079d + 4f75d06 commit d288690

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/LiveComponent/src/EventListener/LiveComponentSubscriber.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ public function onKernelResponse(ResponseEvent $event): void
282282
$request = $event->getRequest();
283283
$response = $event->getResponse();
284284

285+
if (!$event->isMainRequest()) {
286+
return;
287+
}
288+
285289
if (!$this->isLiveComponentRequest($request)) {
286290
return;
287291
}

src/LiveComponent/tests/Functional/Controller/BatchActionControllerTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,40 @@ public function testRedirect(): void
154154
;
155155
}
156156

157+
public function testRedirectWithAcceptHeader(): void
158+
{
159+
$dehydrated = $this->dehydrateComponent($this->mountComponent('with_actions'));
160+
161+
$this->browser()
162+
->throwExceptions()
163+
->get('/_components/with_actions', ['query' => ['props' => json_encode($dehydrated->getProps())]])
164+
->assertSuccessful()
165+
->interceptRedirects()
166+
->use(function (Crawler $crawler, KernelBrowser $browser) {
167+
$rootElement = $crawler->filter('ul')->first();
168+
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
169+
170+
$browser->post('/_components/with_actions/_batch', [
171+
'body' => [
172+
'data' => json_encode([
173+
'props' => $liveProps,
174+
'actions' => [
175+
['name' => 'redirect'],
176+
['name' => 'exception'],
177+
],
178+
]),
179+
],
180+
'headers' => [
181+
'Accept' => ['application/vnd.live-component+html'],
182+
'X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value'),
183+
],
184+
]);
185+
})
186+
->assertStatus(204)
187+
->assertHeaderContains('X-Live-Redirect', '1')
188+
;
189+
}
190+
157191
public function testException(): void
158192
{
159193
$dehydrated = $this->dehydrateComponent($this->mountComponent('with_actions'));

0 commit comments

Comments
 (0)