How to do a normal redirect from turbostream request?

Using target _top indeed ruins the benefit of putting the form in a turbo_frame. Personally I’ve found that it also just doesn’t work with redirect responses and I’m confused as to why I keep seeing it recommended.

There’s a bunch of posts expressing confusion about this exact issue. See:

  1. Turbo and form redirects (again!)
  2. Form redirects not working as expected
  3. Break out of a frame during form redirect - #6 by adamsestra
  4. Redirect to new page on successful form submission, rerender otherwise · Issue #138 · hotwired/turbo · GitHub

The form replacement is great for errors, but when the form succeeds and gets a redirect response, Turbo, by design, doesn’t follow it. Confusing, right?

My recommendation is to disable Turbo on any form that has a redirect response. Seems crazy but the alternative of using a hack to call Turbo.visit after Turbo doesn’t render the redirect is worse IMO. The only forms where I have Turbo enabled are ones where the success response can just replace the form with a success message. For example when the user has to go click a confirm link in their email.

2 Likes