Commit aa39599
committed
Introduce
Introduces the `Turbo::Stream::Redirect` concern to introduce the
`#break_out_of_turbo_frame_and_redirect_to` and
`#turbo_stream_redirect_to` methods. The
`#break_out_of_turbo_frame_and_redirect_to` draws inspiration from the
methods provided by the [Turbo::Native::Navigation][] concern.
When handling requests made from outside a `<turbo-frame>` elements
(without the `Turbo-Frame` HTTP header), respond with a typical HTML
redirect response.
When handling request made from inside a `<turbo-frame>` element (with
the `Turbo-Frame` HTTP header), render a `<turbo-stream action="visit">`
element with the redirect's pathname or URL encoded into the
`[location]` attribute.
When Turbo Drive receives the response, it will call `Turbo.visit()` with
the value read from the `[location]` attribute.
```ruby
class ArticlesController < ApplicationController
def show
@Article = Article.find(params[:id])
end
def create
@Article = Article.new(article_params)
if @article.save
break_out_of_turbo_frame_and_redirect_to @Article
else
render :new, status: :unprocessable_entity
end
end
end
```
Response options (like `:notice`, `:alert`, `:status`, etc.) are
forwarded to the underlying redirection mechanism (`#redirect_to` for
`Mime[:html]` requests and `#turbo_stream_redirect_to` for
`Mime[:turbo_stream]` requests).
This enables server-side actions to navigate the entire page with a,
regardless of the provenance of the request.
Typically, an HTTP that would result in a redirect nets two requests:
the first submission, then the subsequent GET request to follow the
redirect.
In the case of a "break out", the same number of requests are made: the
first submission, then the subsequent GET made by the `Turbo.visit`
call.
To support this behavior, this commit introduces the first
`@hotwire/turbo-rails`-specific Turbo `StreamAction`: the
`turbo-stream[action="visit"]`.
[Turbo::Native::Navigation]: https://github.com/hotwired/turbo-rails/blob/v2.0.11/app/controllers/turbo/native/navigation.rbturbo-stream[action=visit] and #break_out_of_turbo_frame_and_redirect_to
1 parent aee95a8 commit aa39599
File tree
15 files changed
+211
-159
lines changed- app
- assets/javascripts
- controllers/turbo/streams
- helpers/turbo/streams
- javascript/turbo
- models/turbo/streams
- views/turbo/streams
- lib/turbo
- test
- dummy/app
- controllers
- views/layouts
- streams
- system
15 files changed
+211
-159
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5437 | 5437 | | |
5438 | 5438 | | |
5439 | 5439 | | |
| 5440 | + | |
| 5441 | + | |
| 5442 | + | |
| 5443 | + | |
5440 | 5444 | | |
5441 | 5445 | | |
5442 | 5446 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 4 | + | |
8 | 5 | | |
9 | | - | |
10 | | - | |
11 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
12 | 43 | | |
13 | | - | |
14 | | - | |
| 44 | + | |
| 45 | + | |
15 | 46 | | |
| 47 | + | |
| 48 | + | |
16 | 49 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
23 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
24 | 77 | | |
25 | 78 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
11 | 19 | | |
12 | 20 | | |
13 | 21 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
247 | 256 | | |
248 | 257 | | |
249 | 258 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
0 commit comments