-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Description
Which @angular/* package(s) are the source of the bug?
router
Is this a regression?
No
Description
When using Server Side Rendering with scrollPositionRestoration turned on, the browser window is scrolled to the top when the app hydrates. You can scroll down to anywhere on the page while the application loads and it will be scrolled back to top. It is not because a hydration error or missing event replay. It is explicitly stated in the RouterScroller class. (
| this.viewportScroller.scrollToPosition([0, 0]); |
The this.viewportScroller.scrollToPosition([0, 0]); call runs when the scrollPositionRestoration turned on.
I think this function call should not called on the initial navigation as it has bad UX and you unable to control it in your own application. The only way is to disable scrollPositionRestoration, but then it creates other UX problems.
I don't see that this problem has been reported previously, but the code regarding this part has not changed in 7 years, so this problem is there since a long time ago.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/stackblitz-starters-fy2jml6f
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 20.3.6
Node: 22.12.0
Package Manager: npm 10.9.0
OS: linux x64
Angular: 20.3.6
... build, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-server, router, ssr
Package Version
------------------------------------
@angular-devkit/architect 0.2003.6
@angular-devkit/core 20.3.6
@angular-devkit/schematics 20.3.6
@schematics/angular 20.3.6
rxjs 7.8.2
typescript 5.9.3
zone.js 0.15.1
Anything else?
No response