OK I am going to have to hand this off to @eviltrout, it seems that a lot of the pain here is coming from scrollTopFor (which is calling offsetCalculator 3 times for some reason - do we know why ?)
https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/offset-calculator.js.es6
It is entirely possible that this is due to some internal changes in jQuery regarding #offset however I can oddly get reasonable results bypassing it altogether and just using this in lock on:
elementTop() {
const selected = $(this.selector);
if (selected && selected.offset && selected.offset()) {
const result = selected.offset().top;
return (result - $('header').outerHeight()) - 10;
//return result - Math.round(scrollTopFor(result));
}
}
The repro of the issue happens when you make a very narrow window, it trades in percentages of height so being off a few pixels gets amplified big time on narrow displays.
So I guess my big question is, do we need to carry all this fancy or should we simply amend it to always try to place the post highlighted a few pixels below header? I get that there may be some value in displaying 1 previous post IF you can fit current post entirely on-screen, but this does feel somewhat more complex to wrangle.
Note, the regression is likely my fault and in particular jQuery changes, however I think we should revisit the basics here and decide how much fancy we need?