I had tested turbo, It looks simple and promise but I had some doubts:
on the frontend I put:
<!-- index.html -->
<turbo-frame target="_top" id="messages" src="/message">
<div>
custom messages will replace with /message
</div>
</turbo-frame>
On my backend, I had a setup a new view and URL: /message
<!-- message.html -->
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
message end
When I try. I see turbo fetch the /message on the network tab of chrome. But the content not replaced when I see the intro video again. I realize I need to use:
<!-- message.html -->
<turbo-frame id="messages">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
message end
</turbo-frame>
Then all turbo-frame tag will replace with other turbo-frame what comes on the responseā¦
Why is designed that form? Not will be easier only to put the response.
Hey. from my understanding the reasoning is that you can have a ācompleteā page e.g. with Navigation and everything. But when you want to fetch its ācontentā part via turbo-frame it works automagically. So if you have two complete pages with nav and everything but both their content is inside tags, then they can easily reference themselves out of the box and only the content will be replaced.
That seems to be the standard turbo way, if Iām not mistaken this is what dhh call ācontextsā, you need to specify the context at the initial view as well as the final view, you can notice that the same html.erb file could serve many different contexts. Iām still getting used to this āapproachā as wellā¦ I have so many questions, but Iām super excited.
you can build a site that works both for someone with javascript enabled and someone that does not, and
it might simplify the build and test process, and the strongest reason:
if you already have a large site you can start embedding forms without breaking the old code.
For example, you can write a full edit form with headers, navbar, footer, etc. Make this work with the āold-fashionedā way. Then markup the part of this form that you want to embed, by wrapping it in a turbo frame. (For a lazy-loaded frame the idea is similar, but I think you need a noscript tag to render the old-fashioned links.)
Yes, you can have many turbo-frame in the same html.erb. I canāt claim you should, but I think itās been built to allow this kinda of thing.
Iām kinda newbie in terms of hotwire ( everyone seems to be ), but I couldnāt update many turbo-frames at once, It seems that every action ( button, link ) is tied to one turbo-frame, thus updates only one turbo-frame
I think there is a variety of benefits, as dhh explains, but we are also going back to the SSR and re-learning how to build things again. Not sure your answer was about the turbo-frame , mine was a generic one though.
tldr: When you had a large project with 3000 part views for a page you can replace the 3K views with only 5 views. Thatās the reason for use a turbo-frame replace with other turbo-frame.