I just encountered a strange behaviour in my current RoR web app: every time I use the browser's back button (multiple browsers tested, safe mode included), the GET request is being sent multiple times, duplicated. Sometimes twice, but up to 5 times in a row in under 3 seconds. This also causes the SQL queries to run multiple times, doing the same thing.
If I use links to go back, or paste URLs to access the previous page, this does not happen.
Did anyone encounter this, or know what could cause it?
Thanks for your help!
Best,
Alex
Although I've found this to be caused by other issues, the main cuprit is Turbolinks.
Basically, Turbolinks loads the body of your new view via ajax, instead of pulling the whole page (it's meant to speed up the application in production).
It's often the case that Turbolinks will cause issues such as duplicate requests when pressing the back button etc... although to get it with every browser is very strange.
--
Due to a lack of code, I can only speculate on this issue.
It's probably wrong, but a good test to see if it replicates is to remove the references to turbolinks in your JS files; specifically:
#app/assets/javascripts/application.js
//= require turbolinks <- remove this line and see if it fixes the issue
I'll happily delete the answer if it's inappropriate. You'd be best putting up a public repo so that people can see what infrastructure you have.
For me, I realised that the issue was caused by javascript_include_tag out of head tag in aplication.html.erb.
After moving to correct place (inside head tag, right after stylesheet_link_tag) the multiple requests was gone!
Related
I am using a service-worker to cache javascript files. It is written using Workbox.
I ran into a problem that after the browser takes the cached file for execution, it is 3 bytes smaller than the original one - at some point, three spaces disappear from it, due to the absence of which the code turns out to be broken.
Three occurrences of the code 0 .toFixed() (this is a valid construct that my minifier made) have a space removed, due to which it turned into an invalid construct 0.toFixed(). It's like an additional (broken) minifier appears in the caching process.
What could be the reason?
I tried to check if Workbox is the culprit. I wrote a simple worker without it. The problem is gone. But since then I haven't been able to reproduce it at all, even going back to the original code, so I'm stumped and can't analyze the problem myself.
I'm working on a rather large legacy web app with the following stack: nginx, Django, React with React Router.
My problem is that any URL that I load gets a # appended to one before end if the last char is a /.
So https://dev.local/feed/ becomes https://dev.local/feed/#/,
and https://dev.local/create/?fid=user8:13/ becomes https://dev.local/create/?fid=user8:13#/.
I've investigated everything on the front end side. I'm using browserRouter, not hashRouter. I only have one router in my front end. I suspect this is coming from the back end, but not ruling out the front end. Edit: tried completely commenting out the router - the problem persists.
My question is how do I generally approach debug something like this? Browser debug tools - console, network, etc are not showing any redirects or URL rewrites. What would work here?
The issue disappeared after I ripped out a large node module with a lot of subdependancies (old version of spectacle). The list of subdependencies is quite extensive, and it's hard to pinpoint what solved the problem. Nothing obvious could be seen, like multiple version of react-router or history modules.
I'm using Google Tag Manager with a Rails 4.2 app with turbolinks. I'm completely stumped and am completely unable to use Google Tag Manager effectively with turbolinks.
Google tag manager seems to repeatedly sense new page loads (the <body> tag getting replaced) as new installations of google tag manager. When I look at my Google tag assistant recordings I just see an endless sea of Green Tags for Google Tag Manager.
Anyone have any leads on resources where I can figure out how to use it effectively?
I've looked at Googletagmanager with Turbolinks which seems to be slightly dated, but also doesn't solve my problem of errant installations.
Replacing the tag will may all kinds of side effects (as you now realize, one being that the code is re-initialized and fires gtm.js events), so I suggest you drop the noscript part and move the rest to the head - I don't really know turbolinks (or RoR), but according to this article turbolinks will not reload the head.
Unfortunately there still might be side effects in an SPA since all items pushed to the dataLayer will just stay there. You might want to consider reseting the dataLayer when you load new content:
window.google_tag_manager[{{Container ID}}].dataLayer.reset();
Where {{Container ID}} is (obviously) the GTM-XXX id for your container. Don't just over the dataLayer variable with an uninitialized array (dataLayer = []) since GTM adds some methods to the dataLayer variable that will get lost if you overwrite it, and your GTM instance will stop to work.
I'm getting a weird error while trying to click on a Capybara Element
I'm using find(:xpath,"//a[contains(text(),'Connect')]").click
(find(:xpath,"//a[contains(text(),'Connect')]").present? return true)
the error I get is:
Selenium::WebDriver::Error::MoveTargetOutOfBoundsError Exception: Element cannot be scrolled into view:javascript:void(0);
i did some research and the only solution i found is that setting the selenium version to 2.16 may fix this issue (i'm using 2.25).
anybody got an idea?
It may happen when the page being tested is not fit into the current window size. If you know such pages where usually these error happening, you may explicitly scroll down before doing the operation on such hidden elements(like click, clear etc). Here the code to explicitly scroll down the page.
In java,
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("javascript:window.scrollBy(250,350)");
From the times I used selenium webdriver to test .NET apps, I would get that error when the issue was exactly what it sounds like: It's looking for an object on the page that it cant scroll to for some reason. In my case it was because some dialogue boxes would appear without scrollbars and the driver had no way to "scroll the object into view"
Can you watch the execution of your test and see if that's the case? I had some luck rolling back to a previous version of firefox because 15+ was (as of about 2 months ago when I had the issue) unsupported by web driver and had this problem periodically. Rolling back selenium versions may help too.
First step though is definitely to watch the execution of the test and see whats happening though. And a good debugging idea may be to try to work through your steps manually yourself to make sure the test works by hand.
Its also worth noting that for the webdriver to be able to execute click the object actually has to be visible. IsPresent doesnt require that, it just searches the page files. Also an issue I ran into. IsPresent will still return true for objects that are not and cannot be made visible on the page (i.e. something at the bottom of the page that you cant see at the time)
Couple of tips here:
Webdriver should ideally be on the most recent update, it's what most use (Unless you're doing Ruby Automation)
Use css selectors, xpath (Whilst rendered), is almost always heavier on both resources and code.
Try defensive coding, first of all ascertain it exists. There are many ways to do that dependent on what package you are using. In ruby you would do page.has_css?('css_string')
A website of mine is behaving weirdly. The layout sometimes is fine, and sometimes it is screwy. An example page that I see the problem on is this one: link
Disclaimer: I have yet to start my investigation into cause in earnest. I am turning to Stackoverflow because I am lazy and I hope someone will say "That happened to me once, it is probably this...". So please, no one get stuck into this working out this issue if it is something you have never seen before, as it wouldn't be fair as I have not done it myself.
Ok, some background:
The problem usually (maybe always) occurs when first viewing the page
The problem does not show up always, only sometimes
When the page shows up munged, if you refresh it usually reloads looking as it should
The site is a rails app
The css is passed through the neat Smurf Gem, which automatically minifies the CSS and Javascript on the page.
The layout problems happen in firefox (both linux and winXP)
The CSS is served up in the production environment using the ":cache => true" option which concatenates all the css files into one file
Anyway, I am hoping that this has happened to someone before and it will be really simple to fix. If not, I'll go and investigate and return with the solution (or a request for more help).
Thanks in advance!
James.
[edit]I added the first two bullet points, inspired by the comments and first answer[/edit]
We have had something similar when using HAML and SASS that resulted in the CSS being completely unavailable. It only happened on deploys. We determined it was a combination of the Rails stylesheet merging and the generation of the CSS from SASS. Sass was not done generating the CSS, which it did so on the first request to the application, when Rails attempted to merge it all together. The result, a corrupt useless CSS file. Then we stumbled upon this article which has a solution for preventing this issue.
Based on all this, my best guess is that the Smurf gem is attempting to generate your file on the first request, but Rails is serving it out before its done. The generation completes then each following request is fine. If this is the problem then the only solution i know of is to get the file generated before the first request. Of course, this does assume that it is related to deployments or application restarts in some way.
Peer
I had such a problem. The problem was only at the first time the page was loaded. Just reload it and it was fine.
The problem in my case was that the images where not there in the cache for the first time so the browser didnt know it's dimensions when preparing the page which caused the problem
If an image doesn't have a height/width assigned to it, a place is created on the page and it's put there. If the image doesn't quite fit, the browser may not know this until it's refreshed. Then it already knows the size and can properly fit it onto the page.