-
Notifications
You must be signed in to change notification settings - Fork 621
Double request when changing layout in Rails 5 #204
Comments
I'm guessing that Turbolinks is detecting a change in tracked assets when you switch layouts. It performs a visit, decides that assets have changed, and issues a full reload: two requests. Do your layouts have tracked asset tags that differ? |
You are right. That's exactly what appears to be happening. Thanks! In application layout, I have and in admin layout, I have Just to test, I tried including the 'application' manifests in the admin layout and the double requests stopped immediately. It's not a huge problem, as this only happens when switching from one layout to the other. However if i do a server redirect via redirect_to and the layout changed, the double request invalidates any flash message I had set in the controller. In fact this is exactly how I noticed that double requests were happening. |
Our layout setup is identical to what @flamontagne described, and we were able to prevent i.e. On a page using the application.html layout... <%= link_to 'Admin', admin_path, data: { turbolinks: false } %> While it still doesn't address the concern with flash messages, it helped us work around the double-firing issue in the meantime. |
Any solution to this issue? I'm having the same problem, the double request clears the flash notice. |
For now I have decided to setup another controller for my redirect links if I really want the flash message to show. I hope I could see a better solution. I have decided to keep the flash using |
What about using request.head? in a controller decorator/ActionController base class to preserve the flash if the request is head only? |
@fedegos I do not understand how you solve the problem? |
I haven't tried it yet. I will see if that may work as a workaround. |
To get the best out of Turbolinks, it is best to avoid tracked asset changes as much as possible. If that's unavoidable, then try to steer-clear of setting flash messages which may appear on different layouts 😬 And if that's unavoidable, you might have to get creative with a solution to solve your use-case. Hope that helps! |
Did anyone find a workable solution? It's quite a common use-case to have a frontend controller redirect to an admin controller after a successful sign in — whilst setting a flash notice to 'Successfully signed in' for example. I can't find a way around this. |
Whenever I click on a link or do a server redirect where the layout changes (for example going from the 'admin' layout to the 'application' layout), there are two requests that occur on the server.
Both layouts have their own js manifest file with the //= require turbolinks directive.
Any idea?
The text was updated successfully, but these errors were encountered: