File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,11 @@ export function InnerLayoutRouter({
167
167
focusAndScrollElementRef . current . focus ( )
168
168
// Only scroll into viewport when the layout is not visible currently.
169
169
if ( ! topOfElementInViewport ( focusAndScrollElementRef . current ) ) {
170
+ const htmlElement = document . documentElement
171
+ const existing = htmlElement . style . scrollBehavior
172
+ htmlElement . style . scrollBehavior = 'auto'
170
173
focusAndScrollElementRef . current . scrollIntoView ( )
174
+ htmlElement . style . scrollBehavior = existing
171
175
}
172
176
}
173
177
} , [ focusAndScrollRef ] )
Original file line number Diff line number Diff line change @@ -688,7 +688,11 @@ function doRender(input: RenderRouteInfo): Promise<any> {
688
688
}
689
689
690
690
if ( input . scroll ) {
691
+ const htmlElement = document . documentElement
692
+ const existing = htmlElement . style . scrollBehavior
693
+ htmlElement . style . scrollBehavior = 'auto'
691
694
window . scrollTo ( input . scroll . x , input . scroll . y )
695
+ htmlElement . style . scrollBehavior = existing
692
696
}
693
697
}
694
698
Original file line number Diff line number Diff line change @@ -655,6 +655,14 @@ interface FetchNextDataParams {
655
655
unstable_skipClientCache ?: boolean
656
656
}
657
657
658
+ function handleSmoothScroll ( fn : ( ) => void ) {
659
+ const htmlElement = document . documentElement
660
+ const existing = htmlElement . style . scrollBehavior
661
+ htmlElement . style . scrollBehavior = 'auto'
662
+ fn ( )
663
+ htmlElement . style . scrollBehavior = existing
664
+ }
665
+
658
666
function tryToParseAsJSON ( text : string ) {
659
667
try {
660
668
return JSON . parse ( text )
@@ -2141,7 +2149,7 @@ export default class Router implements BaseRouter {
2141
2149
// Scroll to top if the hash is just `#` with no value or `#top`
2142
2150
// To mirror browsers
2143
2151
if ( hash === '' || hash === 'top' ) {
2144
- window . scrollTo ( 0 , 0 )
2152
+ handleSmoothScroll ( ( ) => window . scrollTo ( 0 , 0 ) )
2145
2153
return
2146
2154
}
2147
2155
@@ -2150,14 +2158,14 @@ export default class Router implements BaseRouter {
2150
2158
// First we check if the element by id is found
2151
2159
const idEl = document . getElementById ( rawHash )
2152
2160
if ( idEl ) {
2153
- idEl . scrollIntoView ( )
2161
+ handleSmoothScroll ( ( ) => idEl . scrollIntoView ( ) )
2154
2162
return
2155
2163
}
2156
2164
// If there's no element with the id, we check the `name` property
2157
2165
// To mirror browsers
2158
2166
const nameEl = document . getElementsByName ( rawHash ) [ 0 ]
2159
2167
if ( nameEl ) {
2160
- nameEl . scrollIntoView ( )
2168
+ handleSmoothScroll ( ( ) => nameEl . scrollIntoView ( ) )
2161
2169
}
2162
2170
}
2163
2171
You can’t perform that action at this time.
0 commit comments