Issue 3252: CodeMirror scrolling randomly jumps around while commenting on large (>4000 line) file
Status:  New
Owner: ----
Project Member Reported by sop@google.com, Mar 17, 2015
Trying to review this 4000-line file:

  https://go-review.googlesource.com/#/c/7046/6/src/cmd/internal/obj/arm64/asm7.go.

When we try to add comments, Gerrit seemingly randomly scrolls back to an earlier point in the file. It can happen when finishing a comment, it can happen when starting a comment, it can happen when in the middle of typing text into the comment box. It's been happening for at least around a week, but maybe it's much older than that: we don't usually review such large files.

Attempting to expand the comments on line 912 triggered this bug at least once.

Apr 1, 2015
#1 elijahta...@chromium.org
I've seen this since we switched to the new gerrit UI for chromium-review.googlesource.com.  I used to be able to workaround by picking a different Rendering speed in the config, but now that appears to be locked as "Fast".

I like viewing whole file context most of the time, and navigate to individual comments and diffs, and this makes scrolling unusable a lot of the time.
Apr 1, 2015
Project Member #2 bklarson@gmail.com
My current work-around for this is to select a line in the diff and scroll with up/down (or j/k).  $DAYJOB is slightly behind on Gerrit versions though, so I'm not positive this works on the latest release.

I've also seen it on some smaller files, but seems much more common on larger ones.
Aug 18, 2015
#3 keun...@gmail.com
I don't know if this is related, but trackpad scrolling on OS X Yosemite with latest Chrome also seems to trigger random jumping. I can file that behavior as a separate ticket if you want, but it sounds like bklarson's comment in this thread was about scrolling, not writing/editing comments (or maybe I misunderstood his workaround suggestion). Anyway it sounds like the scrolling glitches might be related.

Searching reveals that CodeMirror seems to have had issues related to scrolling in WebKit dating back to 2012:

https://github.com/adobe/brackets/issues/208

On the other hand, for me, this is only showing up fairly recently, so it could be something else. A few months ago, when my company was running an old build of gerrit, this wasn't an issue; we've upgraded gerrit a few times in the interim and I don't have a precise idea when it broke. Of course it could also be a recent WebKit change, or OS X change, or...

Scrolling seems more consistent in Firefox. (Firefox is also somewhat slower in general for gerrit, unfortunately.)

FWIW I also found this old blog post from a CodeMirror dev about what they do (or were doing, back in 2012); it sounds like they're trying hard to be clever.

http://marijnhaverbeke.nl/blog/a-pathological-scrolling-model.html

At this point, I wish there were a way to toggle CodeMirror (or gerrit's use of it?) into a mode where it just rendered the whole diff DOM and didn't do anything to mess with the scroll behavior. Modern developer machines/browsers are fast. For typical files, it would probably be fast enough.
Aug 18, 2015
#4 keun...@gmail.com
Hmm, strike the above re: Firefox. Scrolling's not really much better, it's just flaky in different exciting ways.
Oct 23, 2015
#5 bclay...@google.com
Aside from the frustration of the code jumping when scrolling, I've now also started to get some jumps occurring when trying to type into a comment box. This bug is making some code reviews near impossible. 
Please can we have this bug assigned to somebody?
Oct 23, 2015
Project Member #6 ekem...@google.com
 > I've now also started to get some jumps occurring when trying to type into a
 > comment box.

For me this kind of jumping happens whenever I have some text selected that is outside the visible area. When the selection is cleared, typing comments works normally again.
Can you check if in your case it's also related to having a text selection? 
Oct 23, 2015
#7 bclay...@google.com
I'll keep an eye out for this in the future and report back.

In this particular case, I wasn't even touching the keyboard when it would decide to jump somewhere the comment box was not visible. It seemed to happen about a second after I'd scroll it back into view. I suspected there was some sort of AJAX notification handler that was causing the UI to move around, but that's pure speculation.
Dec 22, 2015
Project Member #8 dougk....@gmail.com
A workaround here may be to use the "Slow Rendering" option in the diff preferences.  Obviously, this isn't an optimal case, but at least it works reliably?
Dec 22, 2015
#9 keun...@gmail.com
> A workaround here may be to use the "Slow Rendering" option in the diff preferences.  Obviously, this isn't an optimal case, but at least it works reliably?

Nope. After much experimentation with preferences, I've observed similar behaviors observed with slow rendering and every other combination of settings I can find.
Dec 22, 2015
Project Member #10 dougk....@gmail.com
Interesting.  Then again, I reproduced the bug expanding the comment on line 912 as Shawn suggested, signed into the server, and then found it worked completely fine without changing anything.  So, maybe there's another element I'm not accounting for somewhere.  At least on the file that seems to reproduce the issue quite well internally, slow rendering seemed to help (and when I turned it back off, it got worse again), but obviously this isn't proof of anything.