From 3f6602384fe5185b3cbd9a260f8b7ae085367767 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Sun, 31 Jul 2022 18:01:03 -0400 Subject: [PATCH] "Break out" of a frame from the server Closes https://github.com/hotwired/turbo/issues/257 Closes https://github.com/hotwired/turbo/pull/397 Follow-up to https://github.com/hotwired/turbo/issues/257#issuecomment-1143999625 https://github.com/hotwired/turbo/issues/257#issuecomment-1144629360 Depends on https://github.com/hotwired/turbo/pull/660 Introduces the `Turbo::Stream::Redirect` concern to override the [redirect_to][] routing helper. When called with a `turbo_frame:` option, the `redirect_to` helper with check whether the request was made with the Turbo Stream `Accept:` header. When it's absent, the response will redirect with a typical HTTP status code and location. When present, the controller will respond with a `` element that invokes [Turbo.visit($URL, { frame: $TURBO_FRAME })][hotwired/turbo#649] where `$URL` is set to the redirect's path or URL, and `$TURBO_FRAME` is set to the `turbo_frame:` argument. This enables server-side actions to navigate the entire page with a `turbo_frame: "_top"` option. Incidentally, it also enables a frame request to navigate _a different_ frame. 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. Once the `Turbo.visit` call is made, the script removes its ancestor `