Closed
Description
Currently, using scrollBehavior
adds a scroll listener to record window.pageXOffset
and window.pageYOffset
, which will force the browser into doing layout+repaint when scrolling, resulting in serious scrolling janks on mobile devices.
Since we cannot avoid accessing pageXOffset
and pageYOffset
, here are some improvements I can think of:
- Implement a simple debounce function for the scroll listener, and add a
scrollListenerDebounce
option to router configs, which defaults to 1000ms. This should make accessingpageXOffset
andpageYOffset
only when the user have stopped scrolling for 1000ms. - Add a section in the docs explaining the potential performance issues when using
scrollBehavior
, and the inaccuracy of the recorded scrolling position, caused by the debounce function