Emilio realized me in a review comment, scroll anchoring isn't a silver bullet to adjust scroll position. Indeed it doesn't guarantee the scroll position whenever layout is changed. So for example, a sentence from the spec
At the end of a suppression window, the user agent performs all scroll adjustments that were queued during the window and not suppressed by any suppression trigger during the window.
It doesn't say "the user agent MUST perform" or SHOULD or some such.
That being said, I think querying pageYOffset or scrollY or some such in scroll event handlers is a very common pattern used in the wild. That's quite unfortunate we can't apply scroll anchoring in such cases. So I'd like to propose a new heuristic way to avoid infinite scroll event loop like infinite-scroll-event.tentative.html.
The way is similar to what Chrome does (as Emilio referred in comment 56), but slightly different. The way I have in my mind is;
- Record the current scroll position just before we are trying to apply scroll anchoring if we are in scroll event handlers
- Then at the very next time we are trying to apply scroll anchoring if the recorded scroll position equals to the new position where we are trying to adjust, then we disable later scroll anchoring
This way will break infinite-scroll-event.tentative.html actually, but I think it's better than what Chrome does, not firing scroll event even if the scroll position was changed is weird to me.
Honestly I am not sure this will perfectly work in any cases of the infinite scroll event loops, but even if there are some cases don't work, we could improve the heuristic? It may mis-consider the situation, but it would be okay, since it doesn't mean worse than the current situation because the new heuristic is also involving scroll event handlers. It may miss the infinite scroll event loop, that would be a big problem.