Why a double GET after 303 redirect?

Hello!

In my Rails app I have a logout button which sends a delete to a sessions controller. The controller responds with a 303 redirect to the homepage.

I then see two GETs for the homepage: one as a turbo stream and one as HTML.

The Rails logs look like this:

DELETE "/logout"
Processing by SessionsController#destroy as TURBO_STREAM
Redirected to http://0.0.0.0:3000/
Completed 303 See Other

GET "/"
Processing by PagesController#index as TURBO_STREAM
Completed 200 OK

GET "/"
Processing by PagesController#index as HTML
Completed 200 OK

Is this expected behaviour? Ideally I’d like only one GET so the flash message doesn’t get used up without being seen.

The answer is that the pages controller has no layout (yet, I’m haven’t implemented it) – it’s switched off with layout false – and therefore no importmaps loading Turbo.

When I remove layout false, thus enabling the application layout which I have implemented, logging out results in a single GET as expected.

1 Like

I had a similar problem later: after a 302 (or 303) redirect from posting a form, Turbo was issuing two GETs to the new location.

The problem turned out to be a difference in the <head>: in the new location’s layout I had included the importmap shim for legacy browsers – but I had forgotten to also add it to the form page’s layout.