One of the trickier aspects of working with Hotwire Turbo in Rails is handling authentication failures during turbo-frame requests. When a user’s session expires and they trigger a frame request, you typically want to redirect them to the login page, but if you’re not careful, that login page will render inside the frame instead of taking over the full page or a “No content” message will be rendered.
The Problem
Imagine a user clicks a button that loads content into a <turbo-frame>. Their session has expired, so your authentication logic redirects them to /login. Without intervention, a “No content” message is rendered in the frame, probably not what you want!
The Solution
Add this meta tag to your login page:
<% content_for(:head) do %>
<meta name="turbo-visit-control" content="reload">
<% end %>
When Turbo encounters this meta tag in the response, it forces a full page reload instead of performing its usual drive or frame navigation. This breaks out of any containing frame and ensures your login page takes over the entire viewport.
Where to Add It
In a typical Rails app, add it to app/views/sessions/new.html.erb (or wherever your login form lives). Make sure your layout has <%= yield(:head) %> in the <head> section.
This simple addition ensures a smooth user experience when authentication fails, regardless of whether the request originated from a frame, link, or form.
For more details, check out the Turbo documentation on ensuring specific pages trigger a full reload.