Skip to content

Commit 5158503

Browse files
committed
Allow returning custom turbo streams without template on responses
1 parent 8b7f8c7 commit 5158503

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Http/PendingTurboStreamResponse.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class PendingTurboStreamResponse implements Htmlable, Renderable, Responsable
2222
{
2323
use Macroable;
2424

25+
private array $defaultActions = ['append', 'prepend', 'update', 'replace', 'before', 'after', 'remove', 'refresh'];
26+
2527
private string $useAction;
2628

2729
private ?string $useTarget = null;
@@ -341,7 +343,7 @@ private function contentAsRendering()
341343
*/
342344
public function toResponse($request)
343345
{
344-
if (! in_array($this->useAction, ['remove', 'refresh']) && ! $this->partialView && $this->inlineContent === null) {
346+
if (! in_array($this->useAction, ['remove', 'refresh']) && in_array($this->useAction, $this->defaultActions) && ! $this->partialView && $this->inlineContent === null) {
345347
throw TurboStreamResponseFailedException::missingPartial();
346348
}
347349

tests/Http/TurboStreamResponseTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,26 @@ public function turbo_assert_has_turbo_stream()
6767
))
6868
));
6969
}
70+
71+
/** @test */
72+
public function turbo_allows_custom_actions_with_no_view()
73+
{
74+
$this->assertEquals(
75+
<<<'HTML'
76+
<turbo-stream target="contact-edit-drawer" action="close-drawer">
77+
</turbo-stream>
78+
79+
HTML,
80+
(string) turbo_stream()->action('close-drawer')->target('contact-edit-drawer'),
81+
);
82+
83+
$this->assertEquals(
84+
<<<'HTML'
85+
<turbo-stream target="contact-edit-drawer" action="close-drawer">
86+
</turbo-stream>
87+
88+
HTML,
89+
turbo_stream()->action('close-drawer')->target('contact-edit-drawer')->toResponse(request())->getContent(),
90+
);
91+
}
7092
}

0 commit comments

Comments
 (0)