Topics jumping to wrong post

If I, as another enduser, understood right it is same thing I’m experiencing quite often. Some topic is reloading and one short moment, an eye blink or two, forum is showing some older post and then jump to last visit border. It happened to me few moments ago and I was expecting jump, but it stopped showing an oldie.

So… I can’t code but that sounds like a strange timeout style’ish error - like everything is on the borderline state all the time and after very short lag incident Discourse tries keep pace and shows what ever is on screen at that moment.

Or not even close :joy:

1 Like

This looks very much like a something todo with loading slider interfering with lock on.

When I enabled “slow” mode I can see lockon being called to lock a post onto the screen, but can not see it even rendered, so the positioning is super off.

The entire LockOn class is a bit of a hack, in this case maybe instead of locking and caching a position we do something else? Maybe there is a mechanism to call lock on later after the screen is already populated with rendered topics?

6 Likes

Thanks so much for the clear reproduction steps @Don :pray:

Yup, that’s it! Two things going on here at the same time

  1. Loading slider service needs to remove the still-loading class from the body
  2. LockOn needs to scroll to the right place

They were both scheduled in the afterRender part of Ember’s runloop. And since the ‘lock on’ stuff is technically scheduled first, it was being run first. And so LockOn was running while all the post HTML was in the DOM, but still had display: none. :grimacing:

This PR will move the still-loading class removal to the ‘render’ part of the runloop, which means anything else which is scheduling stuff afterRender will be running once everything is rendered and visible:

Agreed! I didn’t want to touch it as part of this bugfix, but I think we should aim to remove all those hacks.

Reading the comments in the file, it looks like it was originally introduced (10 years ago!) to counteract browser ‘scroll restoration’ features. Nowadays, we use history.scrollRestoration = false to disable that browser feature, so I think that makes most of the old hacks redundant.

Probably best to trial this kind of sensitive change via a theme component first, and then if it all looks good we can merge into core. I imagine removing LockOn will fix a lot of other edge-cases we have with topic scroll position. I’ll aim to try this out in the next couple of weeks :technologist:

7 Likes