9

It happens to me, at least in this site, that sometimes when I press "follow" it glitches to "You’re no longer following this question".

I have to refresh the page to get the expected behaviour.

enter image description here

| |
  • I can't repro this, here or on any other site. You can do this whenever you want? It sometimes happens and sometimes does not? Are you on a mobile device or a device with high latency? Happening to anyone else? – Yaakov Ellis May 25 at 8:35
  • It happens randomly (that I'm aware of), here and in askubuntu wich are the sites I use often. I have no control over it. This happens in my desktop pc, with debian buster and firefox 76. It doesn't seem that anyone is facing the same issue, at least not the audience of this post. – schrodigerscatcuriosity May 25 at 23:43
  • See my answer and the comment below it from SamuelLiew - using any userscripts? – Yaakov Ellis May 26 at 9:22
  • @YaakovEllis Thanks for your time. No, no userscripts. I'll check your answer and let you know any news. – schrodigerscatcuriosity May 29 at 13:49
7

I can't repro this, and as only one user is reporting this issue, I can't justify the opportunity cost on spending more time on this.

That said, I am kind of baffled as to how this is happening, so will explain some of the code logic, and maybe you will see something on your client side that could help to debug this (or force a repro).

When the follow button is clicked, a function runs on the client side that does (among other things):

  1. Disable the button to prevent double-submissions
  2. Identify the PostId of the question/answer on which it is being run
  3. Determine what is the current state (following or not) based on the aria-pressed attribute on the [Follow] button.
    1. If it is true then it means that you are currently following
    2. If it is false then it means that you are not yet following
  4. Reverse this value (current value) to get the new value for after you submit. Saved in variable newIsFollowing
  5. Submit the actual ajax query. On success:
    1. if (newIsFollowing) (ie: if you are trying to follow something that you weren't following before) then display the "you are now following" popover.
    2. else (ie: you were following, and now you are no longer following) then display the toast info message

So based on what you are writing, you are submitting a request to follow (5.1) and getting the feedback notice from a request to unfollow (5.2). So I am just completely stumped as to how this is happening. I would normally blame a double-submission, but that is hard to do with the button being disabled (unless there is something in your browser that is not observing the disabled prop on the button), and even so - if you double-submitted and reloaded the page, you would no longer be following.

Would be good to know the value of aria-pressed on your follow button before you clicked on it, and also to see your network tab to make sure that there is only one ajax call being made.

But like I said, I can't spend more time on this now. Please let me know if something comes up to make the issue more evident.

| |
  • 2
    You might want to check if the user is using any userscripts that is calling StackExchange.question.fullInit(), since that causes the follow link to trigger twice, once to follow and immediately unfollow after. – Samuel Liew May 26 at 9:17
  • Closely related to what @SamuelLiew reports, I've also seen similar double AJAX call issues on other UI elements when StackExchange.question.init() is called by a userscript, in at least some instances. However, I haven't specifically looked at if it affects follow/following. – Makyen May 26 at 10:09
  • @Makyen I just found out that init() calls fullInit() under the hood, for logged-in users, so it makes no difference, and that any userscript using either functions need to rethink whether it is really necessary to call this function. – Samuel Liew May 27 at 7:16
  • 1
    Also, on any page that calls init or fullInit more than once, you get the above error when following any post. Since the function is already used by the site itself, no userscript should be using this. – Samuel Liew May 27 at 7:17
  • @SamuelLiew As with most things, a blanket statement isn't accurate. If a userscript should use those functions depends on what it's doing. Some userscripts should be using them; most shouldn't be using them. Some userscripts might even choose to prevent the page from using those function and choose to only permit the userscript to make calls to those functions. What can and should be said is that there are potential side-effects from those functions being called more than once while certain elements exist in the DOM. Any script which uses those functions needs to be aware of the issues. – Makyen Jun 3 at 4:41
2

This has just happened to me on this question https://stackoverflow.com/questions/62117063/how-to-hide-the-div-with-the-form-and-post-data-to-database-and-show-a-hidden-di

I believe it has something to do with the button "Load new answers". When you have the page open and someone adds a new question then the button appears. Once you dynamically load the new answers the "follow" button seems to glitch. Maybe. It could also be caused by dynamically loaded comments under the question.

This post continues in meta:

Follow button glitches when a new answer is loaded up via AJAX

Dom tree for the button

| |
  • Any chance there are multiple follow buttons in that case, one seen by the user and one seen by the javascript? – John Dvorak May 31 at 14:15
  • @JohnDvorak Sorry, I refreshed the page trying to reproduce it again. I haven't seen any duplicate buttons. There were also no errors in the console. – Dharman May 31 at 14:17
  • When you select by ID, only one element gets returned. If you have a duplicate element, the selector has to pick one, and it might prefer the invisible one. – John Dvorak May 31 at 14:19
  • @JohnDvorak I reproduced it again. I executed $('#btnFollowPost-62117063').length and it says there is only 1 – Dharman May 31 at 14:31
  • Of course. That's the one thing that can't ever return more than one element. Try $("*#...") – John Dvorak May 31 at 14:38
  • @JohnDvorak I tried it few different ways. There is only one element I can find. I am not willing to spend too much time debugging this. I posted on MSE instead meta.stackexchange.com/questions/348704/… – Dharman May 31 at 14:55
  • Good idea. Let me suggest linking this question from there. – John Dvorak May 31 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .