trubo:load gets triggered twice when GET request is a redirect 302
See original GitHub issueHi, is this on purpose and if so, how can I make sure that the first call doesn’t do anything?
I created a test where you can test this problem
Start there the server bundle exec rails s
and open the page localhost:3000
. You
will see a link that points to page 1 but then gets redirected to page 2. On the
first page load, you will see an alert which you then will see twice after
clicking on this link.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (3 by maintainers)
Top Results From Across the Web
How To Fix the HTTP 302 Error (5 Methods)
HTTP 302 codes are useful to temporarily redirect website users to another URL. If you're getting this error code, here are 5 ways...
Read more >Why do I get two redirectResponses when receiving one ...
When using Curl I only get one response and tracedump tells the same, so I am sure that the server sends only one...
Read more >302 Found - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code indicates that the resource requested has been temporarily ...
Read more >Types of Redirects – Which Redirect Should You Use?
Like 301, 302 redirects, you can create a 307 redirect by selecting the 307 Temporary Redirect option from the redirection type in Rank...
Read more >Double Redirect (HTTP 302) issued in Chrome, not IE and ...
Browser redirects back to login page without error message. "We could not process request" NOTE: IE, Firefox and other previous versions of chrome...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just hit this and I can’t think of a way to escape as it is.
Our page also contains javascript that as soon
turbo:load
fires, it will dispatch JS requests for analytics, counting 2 views while only one actually happened.But that’s not all. We have pages that once
turbo:load
fires, dispatch JS POST requests that update the model’slock_version
(Rails’s OptimisticLocking).Since
turbo:load
is firing twice, the app totally breaks because when the response’s HTML actually renders on the screen, the “ghost” render that was previously invoked by Turbo fired the JS POST requests updating thelock_version
unadvertly, so the user already has a stale version in his screen.The browser never triggers ‘DOMContentLoaded’ twice after receiving a 302 or 303 response, but Turbo is.
This has nothing to do with idempotency; the code is totally idempotent as it is.
Lastly, there’s the performance penalty: the browser is initializing a huge Vue application twice, making JS requests to fetch data, and so on. If it was only this, and they were only GET requests, it would be a minor bug, but considering the non-idempotent requests JS can make once
turbo:load
gets fired, this is actually a major problem on pages that can be loaded after a redirect.@feliperaul Amazing!