New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turbo-frame request variant #229
Comments
Closes hotwired#229 --- Mark the request's [variant][] as `:turbo_frame` whenever the `Turbo-Frame:` header is present in the request. Also adds documentation to describe how to achieve the previously built-in layout optimizations. [variant]: https://guides.rubyonrails.org/4_1_release_notes.html#action-pack-variants
Closes hotwired#229 --- Mark the request's [variant][] as `:turbo_frame` whenever the `Turbo-Frame:` header is present in the request. Also adds documentation to describe how to achieve the previously built-in layout optimizations. [variant]: https://guides.rubyonrails.org/4_1_release_notes.html#action-pack-variants
Implements `Request#turbo_frame?` predicate along with the `Request#turbo_frame` accessor. Both read from the `Turbo-Frame:` header. Mark variant as `turbo_frame` when header present --- Closes hotwired#229 Mark the request's [variant][] as `:turbo_frame` whenever the `Turbo-Frame:` header is present in the request. Also adds documentation to describe how to achieve the previously built-in layout optimizations. [variant]: https://guides.rubyonrails.org/4_1_release_notes.html#action-pack-variants
Implements `Request#turbo_frame?` predicate along with the `Request#turbo_frame` accessor. Both read from the `Turbo-Frame:` header. Mark variant as `turbo_frame` when header present --- Closes hotwired#229 Mark the request's [variant][] as `:turbo_frame` whenever the `Turbo-Frame:` header is present in the request. Also adds documentation to describe how to achieve the previously built-in layout optimizations. [variant]: https://guides.rubyonrails.org/4_1_release_notes.html#action-pack-variants
I strongly recommend doing this. It doesn't make a lot of sense to not have an easy way to respond differently to from requests coming externally, and requests coming from internal links. For example, if someone types in a url to the show view of some model, you want to render with the full application layout, but if you are responding in the controller to render only part of the page using turbo-frames, they would only see that. Since I don't like having a bunch of different views that only differ in their file extensions and other minor things, I like to render the same view and use different templates for replacing turbo frames in the dom or rendering the full page. This solution works great to accomplish that. |
Just wanted to drop a link to the gem I am working on that would benefit from this change. The module here dynamically selects a layout based on the request variant: https://github.com/WriterZephos/TurboRouter/blob/main/lib/turbo_router/controller.rbz I am rebuilding the above repo using |
Even though hotwired/turbo#378 (comment) says it shouldn't, this really should have been solved by registering a new media type, which has the added benefit of working with non-rails solutions, is controllable from the content, and allows you to push the turbo frame as a media type argument. I do a lot with media types and content negotiations and in my [experienced] opinion tleish isn't correct. The format of the content is indeed HTML, but it's the same issue of In the same vain, a turbo-frame response actually needs to conform to specific properties (it should contain the same frame) and thus a media type that is an html type is actually appropiate. The API would then be: format.html do
# full document response
end
format.turbo_frame do
# turbo frame response
end
format.turbo_stream do
# turbo stream response
end The proposed Accept header for the turbo library would be:
Order of accepting is then:
So this also means that if you do not want to return a turbo frame: format.html do
# full document response
end
format.turbo_frame do
# turbo frame response
end ...and this also means that if the turbo library detects it's not "frameable", it can send:
...and you then do not need to do #278, because Using a custom header ( |
FYI, @dhh does not like the idea of using variants for turbo-frames
|
Thanks. I had not seen that (yet), but matches how I think about it. Unfortunately I doubt turbo frames will be turned into a media type. |
Edit: Minimizing this as I agree, in hindsight, perhaps a bit off-topic. Initially I thought contributing a use-case might contribute to this issue's discussion, but I see it's a bit different than how I had initially interpreted.Curious to hear what you folks think about this use case... I think I agree with DHH that this feels distinct from usage of media type, fwiw. I have a GET-form that does a bunch of filtering. I use turbo advance so that folks can share the url and see the filtered results. The response is pretty hefty, so I want to show some kind of loading indicator. A typical implementation of a turbo frame that lazily sources the frame contents from another controller solves the problem when visiting this page from somewhere else in the app. The contents of the lazy frame can show a loading indicator, and get swapped out. However, afaict, this leaves me with the following issues:
I can resolve (1) by using some CSS to hide/show the content and spinner based on the presence of the busy attribute on the turbo frame tag. I can resolve (2) by using |
Any interest in adding a turbo-frame request variant to
Turbo::Frames::FrameRequest
?This provides the option to change behavior on controller actions for turbo-frame requests:
see also: hotwired/turbo#378
The text was updated successfully, but these errors were encountered: